Example usage for org.springframework.validation BindingResult rejectValue

List of usage examples for org.springframework.validation BindingResult rejectValue

Introduction

In this page you can find the example usage for org.springframework.validation BindingResult rejectValue.

Prototype

void rejectValue(@Nullable String field, String errorCode);

Source Link

Document

Register a field error for the specified field of the current object (respecting the current nested path, if any), using the given error description.

Usage

From source file:com.jd.survey.web.security.GroupController.java

@Secured({ "ROLE_ADMIN" })
@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String createPost(@RequestParam(value = "_proceed", required = false) String proceed, @Valid Group group,
        BindingResult bindingResult, Principal principal, Model uiModel,
        HttpServletRequest httpServletRequest) {
    log.info("create(): handles " + RequestMethod.POST.toString());
    try {/*from  ww w . ja  v a  2  s .c  o m*/
        User user = userService.user_findByLogin(principal.getName());
        if (proceed != null) {
            if (bindingResult.hasErrors()) {
                populateEditForm(uiModel, group, user);
                return "security/groups/create";
            }
            if (!userService.group_ValidateNameIsUnique(group)) {
                bindingResult.rejectValue("name", "field_unique");
                populateEditForm(uiModel, group, user);
                return "security/groups/create";
            }

            uiModel.asMap().clear();
            group = userService.group_merge(group);

            return "redirect:/security/groups/"
                    + encodeUrlPathSegment(group.getId().toString(), httpServletRequest);

        } else {
            return "redirect:/security/groups";
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }

}

From source file:com.jd.survey.web.security.GroupController.java

@Secured({ "ROLE_ADMIN" })
@RequestMapping(method = RequestMethod.PUT, produces = "text/html")
public String update(@RequestParam(value = "_proceed", required = false) String proceed, @Valid Group group,
        BindingResult bindingResult, Principal principal, Model uiModel,
        HttpServletRequest httpServletRequest) {
    log.info("update(): handles PUT");
    try {/*from   w  ww .  ja v a  2 s .  c  o  m*/
        User user = userService.user_findByLogin(principal.getName());
        if (proceed != null) {
            if (bindingResult.hasErrors()) {
                populateEditForm(uiModel, group, user);
                return "security/groups/update";
            }
            if (!userService.group_ValidateNameIsUnique(group)) {
                bindingResult.rejectValue("name", "field_unique");
                populateEditForm(uiModel, group, user);
                return "security/groups/update";
            }

            if (!userService.group_ValidateGroupEmpty(group)) {
                bindingResult.rejectValue("authorities", "field_validation_checkboxes");
                populateEditForm(uiModel, group, user);
                return "security/groups/update";
            }
            uiModel.asMap().clear();
            group = userService.group_merge(group);
            log.info("redirecting to: " + "redirect:/security/groups/"
                    + encodeUrlPathSegment(group.getId().toString(), httpServletRequest));
            return "redirect:/security/groups/"
                    + encodeUrlPathSegment(group.getId().toString(), httpServletRequest);

        } else {
            return "redirect:/security/groups";
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }
}

From source file:com.jd.survey.web.security.UserController.java

/**
 * Creates a new user/*from w w  w .  ja va 2s . c  o  m*/
 * @param proceed
 * @param user
 * @param bindingResult
 * @param principal
 * @param uiModel
 * @param httpServletRequest
 * @return
 */
@Secured({ "ROLE_ADMIN" })
@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String createPost(@RequestParam(value = "_proceed", required = false) String proceed,
        @Validated({ User.UserInfo.class, User.Password.class }) User user, BindingResult bindingResult,
        Principal principal, Model uiModel, HttpServletRequest httpServletRequest) {
    try {
        User loggedInUser = userService.user_findByLogin(principal.getName());
        if (proceed != null) {
            if (bindingResult.hasErrors()) {
                populateEditForm(uiModel, user, loggedInUser);
                return "security/users/create";
            }
            //check that login is unique
            if (userService.user_findByLogin(user.getLogin()) != null
                    && userService.user_ValidateLoginIsUnique(user) == true) {
                bindingResult.rejectValue("login", "field_unique");
                populateEditForm(uiModel, user, loggedInUser);
                return "security/users/create";
            }
            //check that email is unique
            if (userService.user_findByEmail(user.getEmail()) != null
                    && userService.user_ValidateEmailIsUnique(user) == true) {
                bindingResult.rejectValue("email", "field_unique");
                populateEditForm(uiModel, user, loggedInUser);
                return "security/users/create";
            }
            //check that passwords match
            if (!user.getPassword().equals(user.getConfirmPassword())) {
                bindingResult.rejectValue("confirmPassword",
                        "security_password_reset_confirm_passwords_unmatching");
                populateEditForm(uiModel, user, loggedInUser);
                return "security/users/create";
            }
            if (!user.getConfirmPassword().matches(globalSettings.getPasswordEnforcementRegex())) {
                bindingResult.rejectValue("confirmPassword", globalSettings.getPasswordEnforcementMessage(),
                        this.globalSettings.getPasswordEnforcementMessage());
                populateEditForm(uiModel, user, loggedInUser);
                return "security/users/create";
            }
            uiModel.asMap().clear();
            user = userService.user_merge(user);
            return "redirect:/security/users/"
                    + encodeUrlPathSegment(user.getId().toString(), httpServletRequest);
        } else {
            if (user.getType().equals(SecurityType.I)) {
                return "redirect:/security/users/internal";
            }
            if (user.getType().equals(SecurityType.E)) {
                return "redirect:/security/users/external";
            }
        }
        return "redirect:/security";
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }
}

From source file:com.jd.survey.web.security.UserController.java

/**
 * Updates the user information, except password
 * @param proceed/*from  www  .  jav  a2  s .  c  om*/
 * @param user
 * @param bindingResult
 * @param principal
 * @param uiModel
 * @param httpServletRequest
 * @return
 */
@Secured({ "ROLE_ADMIN" })
@RequestMapping(method = RequestMethod.PUT, produces = "text/html")
public String update(@RequestParam(value = "_proceed", required = false) String proceed,
        @Validated({ User.UserInfo.class }) User user, BindingResult bindingResult, Principal principal,
        Model uiModel, HttpServletRequest httpServletRequest) {
    log.info("update(): handles PUT");
    try {
        User loggedInUser = userService.user_findByLogin(principal.getName());
        if (proceed != null) {
            if (bindingResult.hasErrors()) {
                populateEditForm(uiModel, user, loggedInUser);
                return "security/users/update";
            }
            if (userService.user_findByLogin(user.getLogin()) != null
                    && userService.user_ValidateLoginIsUnique(user) == true) {
                bindingResult.rejectValue("login", "field_unique");
                populateEditForm(uiModel, user, loggedInUser);
                return "security/users/update";
            }
            if (userService.user_findByEmail(user.getEmail()) != null
                    && userService.user_ValidateEmailIsUnique(user) == true) {
                bindingResult.rejectValue("email", "field_unique");
                populateEditForm(uiModel, user, loggedInUser);
                return "security/users/update";
            }
            uiModel.asMap().clear();
            user = userService.user_merge(user);
            return "redirect:/security/users/"
                    + encodeUrlPathSegment(user.getId().toString(), httpServletRequest);

        } else {

            if (user.getType().equals(SecurityType.I)) {
                return "redirect:/security/users/internal";
            }

            if (user.getType().equals(SecurityType.E)) {
                return "redirect:/security/users/external";
            }
        }
        return "redirect:/security";
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }
}

From source file:com.jd.survey.web.security.UserController.java

/**
 * Updates the user information, except password
 * @param proceed//from   w  w  w.j ava2  s  .c  o m
 * @param user
 * @param bindingResult
 * @param principal
 * @param uiModel
 * @param httpServletRequest
 * @return
 */
@Secured({ "ROLE_ADMIN" })
@RequestMapping(value = "/pass", method = RequestMethod.PUT, produces = "text/html")
public String updatepassword(@RequestParam(value = "_proceed", required = false) String proceed,
        @Validated({ User.Password.class }) User user, BindingResult bindingResult, Principal principal,
        Model uiModel, HttpServletRequest httpServletRequest) {
    try {
        User loggedInUser = userService.user_findByLogin(principal.getName());
        if (proceed != null) {
            if (bindingResult.hasErrors()) {
                user.refreshUserInfo(userService.user_findById(user.getId()));
                return "security/users/pass";
            }
            //check that passwords match
            if (!user.getPassword().equals(user.getConfirmPassword())) {
                user.refreshUserInfo(userService.user_findById(user.getId()));
                bindingResult.rejectValue("confirmPassword",
                        "security_password_reset_confirm_passwords_unmatching");
                return "security/users/pass";
            }
            //check RegEx
            if (!user.getConfirmPassword().matches(globalSettings.getPasswordEnforcementRegex())) {
                user.refreshUserInfo(userService.user_findById(user.getId()));
                bindingResult.rejectValue("confirmPassword", globalSettings.getPasswordEnforcementMessage(),
                        this.globalSettings.getPasswordEnforcementMessage());
                return "security/users/pass";
            }
            user.refreshUserInfo(userService.user_findById(user.getId()));
            user = userService.user_updatePassword(user);
            uiModel.asMap().clear();
            return "redirect:/security/users/"
                    + encodeUrlPathSegment(user.getId().toString(), httpServletRequest);
        } else {
            if (user.getType().equals(SecurityType.I)) {
                return "redirect:/security/users/internal";
            }
            if (user.getType().equals(SecurityType.E)) {
                return "redirect:/security/users/external";
            }
        }
        return "redirect:/security";
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }
}

From source file:com.jd.survey.web.settings.DataSetController.java

@Secured({ "ROLE_ADMIN" })
@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String createPost(@RequestParam(value = "_proceed", required = false) String proceed,
        @Valid DataSet dataSet, BindingResult bindingResult, Principal principal, Model uiModel,
        HttpServletRequest httpServletRequest) {
    log.info("create(): handles " + RequestMethod.POST.toString());
    try {/*  www  . ja va  2s.  c o m*/
        User user = userService.user_findByLogin(principal.getName());
        if (!user.isAdmin()) {
            log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo()
                    + " attempted by user login:" + principal.getName() + "from IP:"
                    + httpServletRequest.getLocalAddr());
            return "accessDenied";
        }

        if (proceed != null) {
            if (bindingResult.hasErrors()) {
                populateEditForm(uiModel, dataSet, user);
                return "settings/datasets/create";
            }

            if (surveySettingsService.dataset_findByName(dataSet.getName()) != null && !surveySettingsService
                    .dataset_findByName(dataSet.getName()).getId().equals(dataSet.getId())) {
                bindingResult.rejectValue("name", "field_unique");
                populateEditForm(uiModel, dataSet, user);
                return "settings/datasets/update";
            }

            uiModel.asMap().clear();
            dataSet = surveySettingsService.dataSet_merge(dataSet);
            return "redirect:/settings/datasets/"
                    + encodeUrlPathSegment(dataSet.getId().toString(), httpServletRequest);
        } else {
            return "redirect:/settings/datasets";
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }

}

From source file:com.jd.survey.web.settings.DataSetController.java

@Secured({ "ROLE_ADMIN" })
@RequestMapping(method = RequestMethod.PUT, produces = "text/html")
public String update(@RequestParam(value = "_proceed", required = false) String proceed, @Valid DataSet dataSet,
        BindingResult bindingResult, Principal principal, Model uiModel,
        HttpServletRequest httpServletRequest) {
    log.info("update(): handles PUT");
    try {//  w w  w . ja v  a  2s  .  com
        User user = userService.user_findByLogin(principal.getName());

        if (!user.isAdmin()) {
            log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo()
                    + " attempted by user login:" + principal.getName() + "from IP:"
                    + httpServletRequest.getLocalAddr());
            return "accessDenied";
        }

        if (proceed != null) {
            if (bindingResult.hasErrors()) {
                populateEditForm(uiModel, dataSet, user);
                return "settings/datasets/update";
            }

            if (surveySettingsService.dataset_findByName(dataSet.getName()) != null && !surveySettingsService
                    .dataset_findByName(dataSet.getName()).getId().equals(dataSet.getId())) {
                bindingResult.rejectValue("name", "field_unique");
                populateEditForm(uiModel, dataSet, user);
                return "settings/datasets/update";
            }
            uiModel.asMap().clear();
            dataSet = surveySettingsService.dataSet_merge(dataSet);
            return "redirect:/settings/datasets/"
                    + encodeUrlPathSegment(dataSet.getId().toString(), httpServletRequest);
        } else {
            return "redirect:/settings/datasets";
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }
}

From source file:com.jd.survey.web.settings.QuestionColumnLabelController.java

@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" })
@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String createPost(Question question, BindingResult bindingResult,
        @RequestParam(value = "_proceed", required = false) String proceed, Principal principal, Model uiModel,
        HttpServletRequest httpServletRequest) {
    log.info("create(): handles " + RequestMethod.POST.toString());
    try {//from w  w w.j  a  v  a2 s  .  co m
        String login = principal.getName();
        User user = userService.user_findByLogin(login);
        //Check if the user is authorized
        if (!securityService.userIsAuthorizedToManageSurvey(surveySettingsService
                .question_findById(question.getId()).getPage().getSurveyDefinition().getId(), user)
                && !securityService
                        .userBelongsToDepartment(surveySettingsService.question_findById(question.getId())
                                .getPage().getSurveyDefinition().getDepartment().getId(), user)) {
            log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo()
                    + " attempted by user login:" + principal.getName() + "from IP:"
                    + httpServletRequest.getLocalAddr());
            return "accessDenied";
        }
        if (proceed != null) {
            boolean isValid = true;
            for (int i = 0; i < question.getColumnLabelsList().size(); i++) {
                if (question.getColumnLabelsList().get(i).getLabel() != null
                        && question.getColumnLabelsList().get(i).getLabel().trim().length() > 0) {

                    if (question.getColumnLabelsList().get(i).getLabel().trim().length() == 0
                            || question.getColumnLabelsList().get(i).getLabel().trim().length() > 75) {
                        bindingResult.rejectValue("columnLabelsList[" + i + "].label", "invalidEntry");
                        isValid = false;

                    }
                } else {
                    //User is trying to save an empty MC form
                    if (i == 0) {
                        bindingResult.rejectValue("columnLabelsList[" + i + "].label", "invalidEntry");
                        isValid = false;
                    }
                }
            }

            if (!isValid) {
                return "settings/questionCols/update";
            } else {
                question = surveySettingsService.question_updateColumnLabels(question);
                return "settings/questionCols/saved";

            }
        } else {
            question = surveySettingsService.question_updateColumnLabels(question);
            return "redirect:/settings/surveyDefinitions/" + encodeUrlPathSegment(
                    question.getPage().getSurveyDefinition().getId().toString(), httpServletRequest);
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }

}

From source file:com.jd.survey.web.settings.QuestionController.java

@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" })
@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String create(@RequestParam(value = "_proceed", required = false) String proceed,
        @Valid Question question, BindingResult bindingResult, Principal principal, Model uiModel,
        HttpServletRequest httpServletRequest) {
    log.info("create(): handles " + RequestMethod.POST.toString());

    try {//from www  . ja va 2 s .  c om
        String login = principal.getName();
        User user = userService.user_findByLogin(login);
        //SurveyDefinitionPage surveyDefinitionPage = surveySettingsService.surveyDefinitionPage_findById(surveyDefinitionPageId); 
        //Check if the user is authorized

        if (!securityService.userIsAuthorizedToManageSurvey(question.getPage().getSurveyDefinition().getId(),
                user)
                && !securityService.userBelongsToDepartment(
                        question.getPage().getSurveyDefinition().getDepartment().getId(), user)) {
            log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo()
                    + " attempted by user login:" + principal.getName() + "from IP:"
                    + httpServletRequest.getLocalAddr());
            return "accessDenied";
        }
        //User user = userService.user_findByLogin(principal.getName());
        if (proceed != null) {
            if (bindingResult.hasErrors()) {
                populateEditForm(uiModel, question, user);
                return "settings/questions/create";
            }

            if (!surveySettingsService.question_ValidateDateRange(question)) {
                populateEditForm(uiModel, question, user);
                bindingResult.rejectValue("dateMinimum", "date_format_validation_range");
                return "settings/questions/create";
            }
            //validate Double min max   
            if (!surveySettingsService.question_ValidateMinMaxDoubleValues(question)) {
                populateEditForm(uiModel, question, user);
                bindingResult.rejectValue("decimalMinimum", "field_min_invalid");
                return "settings/questions/create";
            }
            //validate Integer min max   
            if (!surveySettingsService.question_ValidateMinMaxValues(question)) {
                populateEditForm(uiModel, question, user);
                bindingResult.rejectValue("integerMinimum", "field_min_invalid");
                return "settings/questions/create";
            }
            if (question.getType().getIsRating()) {
                SortedSet<QuestionOption> options = new TreeSet<QuestionOption>();
                options.add(new QuestionOption(question, (short) 1, "1", messageSource
                        .getMessage(EXTREMELY_UNSATISFIED_LABEL, null, LocaleContextHolder.getLocale())));
                options.add(new QuestionOption(question, (short) 2, "2",
                        messageSource.getMessage(UNSATISFIED_LABEL, null, LocaleContextHolder.getLocale())));
                options.add(new QuestionOption(question, (short) 3, "3",
                        messageSource.getMessage(NEUTRAL_LABEL, null, LocaleContextHolder.getLocale())));
                options.add(new QuestionOption(question, (short) 4, "4",
                        messageSource.getMessage(SATISFIED_LABEL, null, LocaleContextHolder.getLocale())));
                options.add(new QuestionOption(question, (short) 5, "5", messageSource
                        .getMessage(EXTREMELY_SATISFIED_LABEL, null, LocaleContextHolder.getLocale())));
                question = surveySettingsService.question_merge(question, options);
            }

            //            if (question.getPublishToSocrata().equals(true)){
            //               bindingResult.rejectValue("socrataColumnName", "field_min_invalid");
            //               return "settings/questions/create";   
            //               }

            else {

                Policy questionTextPolicy = Policy
                        .getInstance(this.getClass().getResource(POLICY_FILE_LOCATION));
                AntiSamy emailAs = new AntiSamy();
                CleanResults crQuestionText = emailAs.scan(question.getQuestionText(), questionTextPolicy);
                question.setQuestionText(crQuestionText.getCleanHTML());

                Policy questionTipPolicy = Policy
                        .getInstance(this.getClass().getResource(POLICY_FILE_LOCATION));
                AntiSamy completedSurveyAs = new AntiSamy();
                CleanResults crQuestionTip = completedSurveyAs.scan(question.getTip(), questionTipPolicy);
                question.setTip(crQuestionTip.getCleanHTML());

                question = surveySettingsService.question_merge(question);

            }
            uiModel.asMap().clear();
            return "settings/questions/saved";
        }

        else {
            return "redirect:/settings/surveyDefinitions/" + encodeUrlPathSegment(
                    question.getPage().getSurveyDefinition().getId().toString(), httpServletRequest);
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }

}

From source file:com.jd.survey.web.settings.QuestionController.java

@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" })
@RequestMapping(method = RequestMethod.PUT, produces = "text/html")
public String update(@RequestParam(value = "_proceed", required = false) String proceed,
        @Valid Question question, BindingResult bindingResult, Principal principal, Model uiModel,
        HttpServletRequest httpServletRequest) {
    log.info("update(): handles PUT");
    try {//from ww  w  .  j a  v a  2 s. c  o m
        //User user = userService.user_findByLogin(principal.getName());
        String login = principal.getName();
        User user = userService.user_findByLogin(login);

        //SurveyDefinitionPage surveyDefinitionPage = surveySettingsService.surveyDefinitionPage_findById(surveyDefinitionPageId); surveySettingsService.question_findById(question.getId()).getPage().getSurveyDefinition().getId()
        //Check if the user is authorized
        if (!securityService.userIsAuthorizedToManageSurvey(question.getPage().getSurveyDefinition().getId(),
                user)
                && !securityService.userBelongsToDepartment(
                        question.getPage().getSurveyDefinition().getDepartment().getId(), user)) {
            log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo()
                    + " attempted by user login:" + principal.getName() + "from IP:"
                    + httpServletRequest.getLocalAddr());
            return "accessDenied";
        }
        if (proceed != null) {
            if (bindingResult.hasErrors()) {
                populateEditForm(uiModel, question, user);
                log.info("-------------------------------------------"
                        + bindingResult.getFieldErrors().toString());
                return "settings/questions/update";
            }
            if (!surveySettingsService.question_ValidateDateRange(question)) {
                populateEditForm(uiModel, question, user);
                bindingResult.rejectValue("dateMinimum", "date_format_validation_range");
                return "settings/questions/update";
            }
            if (!surveySettingsService.question_ValidateMinMaxDoubleValues(question)) {
                populateEditForm(uiModel, question, user);
                bindingResult.rejectValue("decimalMinimum", "field_min_invalid");
                return "settings/questions/update";
            }
            if (!surveySettingsService.question_ValidateMinMaxValues(question)) {
                populateEditForm(uiModel, question, user);
                bindingResult.rejectValue("integerMinimum", "field_min_invalid");
                return "settings/questions/update";
            }
            if (question.getSuportsOptions()) {
                //If user wants to modify and existent question without options to Rating type, then use the default values
                int NumberOfQuestionOptions = 0;
                Set<QuestionOption> qOpts = surveySettingsService
                        .questionOption_findByQuestionId(question.getId());
                for (QuestionOption q : qOpts) {
                    NumberOfQuestionOptions++;
                }
                if ((question.getType().toString() == "SMILEY_FACES_RATING"
                        || question.getType().toString() == "STAR_RATING") && NumberOfQuestionOptions != 5) {
                    log.info(
                            "Removing Question Options since the amount of Questions Options for Rating Type cannot be longer than 5 Qoptions");
                    surveySettingsService.questionOption_removeQuestionOptionsByQuestionId(question.getId());
                    SortedSet<QuestionOption> options = new TreeSet<QuestionOption>();
                    options.add(new QuestionOption(question, (short) 1, "1", messageSource
                            .getMessage(EXTREMELY_UNSATISFIED_LABEL, null, LocaleContextHolder.getLocale())));
                    options.add(new QuestionOption(question, (short) 2, "2", messageSource
                            .getMessage(UNSATISFIED_LABEL, null, LocaleContextHolder.getLocale())));
                    options.add(new QuestionOption(question, (short) 3, "3",
                            messageSource.getMessage(NEUTRAL_LABEL, null, LocaleContextHolder.getLocale())));
                    options.add(new QuestionOption(question, (short) 4, "4",
                            messageSource.getMessage(SATISFIED_LABEL, null, LocaleContextHolder.getLocale())));
                    options.add(new QuestionOption(question, (short) 5, "5", messageSource
                            .getMessage(EXTREMELY_SATISFIED_LABEL, null, LocaleContextHolder.getLocale())));
                    //Adding default values to Rating Type Question
                    log.info("Adding default values to Rating Type Question");
                    question = surveySettingsService.question_merge(question, options);
                    uiModel.asMap().clear();
                    return "settings/questions/saved";
                } else {
                    Policy questionTextPolicy = Policy
                            .getInstance(this.getClass().getResource(POLICY_FILE_LOCATION));
                    AntiSamy emailAs = new AntiSamy();
                    CleanResults crQuestionText = emailAs.scan(question.getQuestionText(), questionTextPolicy);
                    question.setQuestionText(crQuestionText.getCleanHTML());

                    Policy questionTipPolicy = Policy
                            .getInstance(this.getClass().getResource(POLICY_FILE_LOCATION));
                    AntiSamy completedSurveyAs = new AntiSamy();
                    CleanResults crQuestionTip = completedSurveyAs.scan(question.getTip(), questionTipPolicy);
                    question.setTip(crQuestionTip.getCleanHTML());

                    question = surveySettingsService.question_merge(question);
                    uiModel.asMap().clear();
                    return "settings/questions/saved";
                }
            }

            question = surveySettingsService.question_merge(question);
            uiModel.asMap().clear();
            return "settings/questions/saved";

        } else {
            return "redirect:/settings/surveyDefinitions/" + encodeUrlPathSegment(
                    question.getPage().getSurveyDefinition().getId().toString(), httpServletRequest);
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }
}