Examples of ValidationErrors


Examples of net.sourceforge.stripes.validation.ValidationErrors

     * @return a Resolution if any interceptor determines that the request processing should
     *         be aborted in favor of another Resolution, null otherwise.
     */
    public static Resolution doCustomValidation(final ExecutionContext ctx,
                                                final boolean alwaysInvokeValidate) throws Exception {
        final ValidationErrors errors = ctx.getActionBeanContext().getValidationErrors();
        final ActionBean bean = ctx.getActionBean();
        final Method handler = ctx.getHandler();
        final boolean doBind = handler != null && handler.getAnnotation(DontBind.class) == null;
        final boolean doValidate = doBind && handler.getAnnotation(DontValidate.class) == null;
        Configuration config = StripesFilter.getConfiguration();

        // Run the bean's methods annotated with @ValidateMethod if the following conditions are met:
        //   l. This event is not marked to bypass binding
        //   2. This event is not marked to bypass validation (doValidate == true)
        //   3. We have no errors so far OR alwaysInvokeValidate is true
        if (doValidate) {

            ctx.setLifecycleStage(LifecycleStage.CustomValidation);
            ctx.setInterceptors(config.getInterceptors(LifecycleStage.CustomValidation));

            return ctx.wrap( new Interceptor() {
        public Resolution intercept(ExecutionContext context) throws Exception {
                    // Run any of the annotated validation methods
                    Method[] validations = findCustomValidationMethods(bean.getClass());
                    for (Method validation : validations) {
                        ValidationMethod ann = validation.getAnnotation(ValidationMethod.class);

                        boolean run = (ann.when() == ValidationState.ALWAYS)
                                   || (ann.when() == ValidationState.DEFAULT && alwaysInvokeValidate)
                                   || errors.isEmpty();

                        if (run && applies(ann, ctx.getActionBeanContext().getEventName())) {
                            Class<?>[] args = validation.getParameterTypes();
                            if (args.length == 1 && args[0].equals(ValidationErrors.class)) {
                                validation.invoke(bean, errors);
View Full Code Here

Examples of net.sourceforge.stripes.validation.ValidationErrors

        Resolution resolution = null;
        if (doValidate) {
            ActionBean bean = ctx.getActionBean();
            ActionBeanContext context = ctx.getActionBeanContext();
            ValidationErrors errors = context.getValidationErrors();

            // Now if we have errors and the bean wants to handle them...
            if (errors.size() > 0 && bean instanceof ValidationErrorHandler) {
                resolution = ((ValidationErrorHandler) bean).handleValidationErrors(errors);
                fillInValidationErrors(ctx);
            }

            // If there are still errors see if we need to lookup the resolution
            if (errors.size() > 0 && resolution == null) {
                logValidationErrors(context);
                resolution = context.getSourcePageResolution();
            }
        }
View Full Code Here

Examples of net.sourceforge.stripes.validation.ValidationErrors

     *
     * @param ctx the ExecutionContext being used to process the current request
     */
    public static void fillInValidationErrors(ExecutionContext ctx) {
        ActionBeanContext context = ctx.getActionBeanContext();
        ValidationErrors errors = context.getValidationErrors();

        if (errors.size() > 0) {
            String formAction = StripesFilter.getConfiguration().getActionResolver()
                    .getUrlBinding(ctx.getActionBean().getClass());
            HttpServletRequest request = ctx.getActionBeanContext().getRequest();

            /** Since we don't pass form action down the stack, we add it to the errors here. */
            for (Map.Entry<String, List<ValidationError>> entry : errors.entrySet()) {
                String parameterName = entry.getKey();
                List<ValidationError> listOfErrors = entry.getValue();

                for (ValidationError error : listOfErrors) {
                    // Make sure we process each error only once, no matter how often we're called
View Full Code Here

Examples of net.sourceforge.stripes.validation.ValidationErrors

        trip.addParameter("two", "not25chars");
        trip.addParameter("three", "3");
        trip.addParameter("four", "onetwothree");
        trip.execute("/Validate.action");

        ValidationErrors errors = trip.getValidationErrors();
        Assert.assertNull(errors.get("one"), "Field one should not have errors.");
        Assert.assertEquals(errors.get("two").size(), 1, "Field two should not have 1 error.");
        Assert.assertEquals(errors.get("three").size(), 1, "Field three should not have errors.");
        Assert.assertEquals(errors.get("four").size(), 1, "Field one should not have errors.");
    }
View Full Code Here

Examples of net.sourceforge.stripes.validation.ValidationErrors

     */
    protected void setFocusOnFieldIfRequired(InputTagSupport tag) {
        // Decide whether or not this field should be focused
        if (this.focus != null && !this.focusSet) {
            ActionBean bean = getActionBean();
            ValidationErrors errors = bean == null ? null : bean.getContext().getValidationErrors();

            // If there are validation errors, select the first field in error
            if (errors != null && errors.hasFieldErrors()) {
                List<ValidationError> fieldErrors = errors.get(tag.getName());
                if (fieldErrors != null && fieldErrors.size() > 0) {
                    tag.setFocus(true);
                    this.focusSet = true;
                }
            }
View Full Code Here

Examples of net.sourceforge.stripes.validation.ValidationErrors

    public Resolution onSave() {
        User user = userService.findUser(sessionUser);

        boolean passwordMatch = this.formUser.isPasswordMatch();
        boolean compliant = this.formUser.isPasswordPolicyCompliant();
        ValidationErrors errors = new ValidationErrors();

        if (!passwordMatch) {
            errors.add("password", new LocalizableError("password.nomatch"));
        }

        if (!compliant) {
            errors.add("password", new SimpleError(passwordPolicy.getDescription()));
        }

        if (errors.size() == 0) {
            user.setFullName(this.formUser.getFullName());
            userService.saveWithPassword(user, this.formUser.getPassword());
            return new ForwardResolution(HOME_ACTION);
        } else {
            getContext().setValidationErrors(errors);
View Full Code Here

Examples of net.sourceforge.stripes.validation.ValidationErrors

            if (value != null) {
                formUser.getRole(value).setAssigned(true);
            }
        }

        ValidationErrors passwordError = new ValidationErrors();

        if (formUser.hasPassword()) {
            boolean passwordMatch = this.formUser.isPasswordMatch();
            boolean compliant = this.formUser.isPasswordPolicyCompliant();

            if (!passwordMatch) {
                passwordError.add("password", new LocalizableError("password.nomatch"));
            }

            if (!compliant) {
                passwordError.add("password", new SimpleError(passwordPolicy.getDescription()));
            }
        }

        if (passwordError.size() == 0) {
            actualUser.setFullName(this.formUser.getFullName());
            actualUser.clearRoles();

            for (FormRole role : formUser.getRoles())  {
                if (role.isAssigned()) {
View Full Code Here

Examples of net.sourceforge.stripes.validation.ValidationErrors

            }
        }

        boolean passwordMatch = this.formUser.isPasswordMatch();
        boolean compliant = this.formUser.isPasswordPolicyCompliant();
        ValidationErrors errors = new ValidationErrors();


        if (!passwordMatch) {
            errors.add("password", new LocalizableError("password.nomatch"));
        }

        if (!compliant) {
            errors.add("password", new SimpleError(passwordPolicy.getDescription()));
        }

        User otherUser = getUserService().findUser(this.formUser.getUsername());
        if (otherUser != null) {
            errors.add("username", new SimpleError("That username is not available"));
        }

        if (formUser.getRoles().isEmpty()) {
            errors.add("roles", new SimpleError("You must select one role"));
        }

        if (errors.size() == 0) {
            User user = new User();
            user.setFullName(this.formUser.getFullName());
            user.setUsername(this.formUser.getUsername());

            user.clearRoles();
View Full Code Here

Examples of net.sourceforge.stripes.validation.ValidationErrors

        return new ForwardResolution(ADD_JOB_JSP);
    }

    @HandlesEvent("SaveOrUpdate")
    public Resolution onSave() {
        ValidationErrors errors = new ValidationErrors();

        if (!job.scriptExists() && job.runOnThisHost()) {
            errors.add("script", new SimpleError(String.format("The script %s does not exist.", job.getScript())));
        }

        if (errors.isEmpty()) {
            job.setLastModified(System.currentTimeMillis());
            getJobService().save(job);
            return new ForwardResolution(INFO_JOB_ACTION + "?job.id=" + job.getId());
        } else {
            getContext().setValidationErrors(errors);
View Full Code Here

Examples of net.sourceforge.stripes.validation.ValidationErrors

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    @HandlesEvent("SaveOrUpdate")
    public Resolution onSave() {

        ValidationErrors errors = new ValidationErrors();

        if (!job.scriptExists() && job.runOnThisHost()) {
            errors.add("script", new SimpleError(String.format("The script %s does not exist.", job.getScript())));
        }

        if (errors.isEmpty()) {
            job.setLastModified(System.currentTimeMillis());
            job.incrementVersion();
            getJobService().save(job);
            return new ForwardResolution(INFO_JOB_ACTION + "?job.id=" + job.getId());
        } else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.