Example usage for org.springframework.web.servlet.mvc.support RedirectAttributes addAttribute

List of usage examples for org.springframework.web.servlet.mvc.support RedirectAttributes addAttribute

Introduction

In this page you can find the example usage for org.springframework.web.servlet.mvc.support RedirectAttributes addAttribute.

Prototype

@Override
    RedirectAttributes addAttribute(String attributeName, @Nullable Object attributeValue);

Source Link

Usage

From source file:org.kuali.rice.krad.lookup.LookupController.java

/**
 * Invoked from the UI to return the selected lookup results lines, parameters are collected to build a URL to
 * the caller and then a redirect is performed.
 *
 * @param lookupForm lookup form instance containing the selected results and lookup configuration
 * @param request servlet request// w w  w . j  a v a 2  s .  c o m
 * @param redirectAttributes redirect attributes instance
 * @return redirect URL for the return location
 */
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=returnSelected")
public String returnSelected(@ModelAttribute(UifConstants.KUALI_FORM_ATTR) LookupForm lookupForm,
        HttpServletRequest request, final RedirectAttributes redirectAttributes) {

    LookupUtils.refreshLookupResultSelections((LookupForm) lookupForm);

    // build string of select line identifiers
    String selectedLineValues = "";

    Set<String> selectedLines = lookupForm.getSelectedCollectionLines().get(UifPropertyPaths.LOOKUP_RESULTS);
    if (selectedLines != null) {
        for (String selectedLine : selectedLines) {
            selectedLineValues += selectedLine + ",";
        }
        selectedLineValues = StringUtils.removeEnd(selectedLineValues, ",");
    }

    Properties parameters = new Properties();

    parameters.put(UifParameters.SELECTED_LINE_VALUES, selectedLineValues);
    parameters.putAll(lookupForm.getInitialRequestParameters());

    String redirectUrl = UrlFactory.parameterizeUrl(lookupForm.getReturnLocation(), parameters);

    boolean lookupCameFromDifferentServer = KRADUtils.areDifferentDomains(lookupForm.getReturnLocation(),
            lookupForm.getRequestUrl());

    if (redirectUrl.length() > RiceConstants.MAXIMUM_URL_LENGTH && !lookupCameFromDifferentServer) {
        redirectAttributes.addFlashAttribute(UifParameters.SELECTED_LINE_VALUES, selectedLineValues);
    }

    if (redirectUrl.length() > RiceConstants.MAXIMUM_URL_LENGTH && lookupCameFromDifferentServer) {
        Map<String, String[]> parms = lookupForm.getInitialRequestParameters();
        parms.remove(UifParameters.RETURN_FORM_KEY);

        //add an error message to display to the user
        redirectAttributes.mergeAttributes(parms);
        redirectAttributes.addAttribute(UifParameters.MESSAGE_TO_DISPLAY,
                RiceKeyConstants.INFO_LOOKUP_RESULTS_MV_RETURN_EXCEEDS_LIMIT);

        String formKeyParam = request.getParameter(UifParameters.FORM_KEY);
        redirectAttributes.addAttribute(UifParameters.FORM_KEY, formKeyParam);

        return UifConstants.REDIRECT_PREFIX + lookupForm.getRequestUrl();
    }

    if (redirectUrl.length() < RiceConstants.MAXIMUM_URL_LENGTH) {
        redirectAttributes.addAttribute(UifParameters.SELECTED_LINE_VALUES, selectedLineValues);
    }

    redirectAttributes.addAttribute(KRADConstants.DISPATCH_REQUEST_PARAMETER,
            KRADConstants.RETURN_METHOD_TO_CALL);

    if (StringUtils.isNotBlank(lookupForm.getReturnFormKey())) {
        redirectAttributes.addAttribute(UifParameters.FORM_KEY, lookupForm.getReturnFormKey());
    }

    redirectAttributes.addAttribute(KRADConstants.REFRESH_CALLER, lookupForm.getView().getId());
    redirectAttributes.addAttribute(KRADConstants.REFRESH_CALLER_TYPE,
            UifConstants.RefreshCallerTypes.MULTI_VALUE_LOOKUP);
    redirectAttributes.addAttribute(KRADConstants.REFRESH_DATA_OBJECT_CLASS,
            lookupForm.getDataObjectClassName());

    if (StringUtils.isNotBlank(lookupForm.getQuickfinderId())) {
        redirectAttributes.addAttribute(UifParameters.QUICKFINDER_ID, lookupForm.getQuickfinderId());
    }

    if (StringUtils.isNotBlank(lookupForm.getLookupCollectionName())) {
        redirectAttributes.addAttribute(UifParameters.LOOKUP_COLLECTION_NAME,
                lookupForm.getLookupCollectionName());
    }

    if (StringUtils.isNotBlank(lookupForm.getLookupCollectionId())) {
        redirectAttributes.addAttribute(UifParameters.LOOKUP_COLLECTION_ID, lookupForm.getLookupCollectionId());
    }

    if (StringUtils.isNotBlank(lookupForm.getReferencesToRefresh())) {
        redirectAttributes.addAttribute(KRADConstants.REFERENCES_TO_REFRESH,
                lookupForm.getReferencesToRefresh());
    }

    // clear current form from session
    GlobalVariables.getUifFormManager().removeSessionForm(lookupForm);

    return UifConstants.REDIRECT_PREFIX + lookupForm.getReturnLocation();
}

From source file:org.kuali.rice.krad.web.controller.LookupController.java

/**
 * Invoked from the UI to return the selected lookup results lines, parameters are collected to build a URL to
 * the caller and then a redirect is performed
 *
 * @param lookupForm - lookup form instance containing the selected results and lookup configuration
 *//*from  w w  w.  ja  v  a  2  s  .  c  o m*/
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=returnSelected")
public String returnSelected(@ModelAttribute("KualiForm") LookupForm lookupForm, BindingResult result,
        HttpServletRequest request, HttpServletResponse response, final RedirectAttributes redirectAttributes) {

    Properties parameters = new Properties();

    // build string of select line identifiers
    String selectedLineValues = "";
    Set<String> selectedLines = lookupForm.getSelectedCollectionLines().get(UifPropertyPaths.LOOKUP_RESULTS);
    if (selectedLines != null) {
        for (String selectedLine : selectedLines) {
            selectedLineValues += selectedLine + ",";
        }
        selectedLineValues = StringUtils.removeEnd(selectedLineValues, ",");
    }

    //check to see what the redirect URL length would be
    parameters.put(UifParameters.SELECTED_LINE_VALUES, selectedLineValues);
    parameters.putAll(lookupForm.getInitialRequestParameters());
    String redirectUrl = UrlFactory.parameterizeUrl(lookupForm.getReturnLocation(), parameters);

    boolean lookupCameFromDifferentServer = areDifferentDomains(lookupForm.getReturnLocation(),
            lookupForm.getRequestUrl());

    if (redirectUrl.length() > RiceConstants.MAXIMUM_URL_LENGTH && !lookupCameFromDifferentServer) {
        redirectAttributes.addFlashAttribute(UifParameters.SELECTED_LINE_VALUES, selectedLineValues);
    }

    if (redirectUrl.length() > RiceConstants.MAXIMUM_URL_LENGTH && lookupCameFromDifferentServer) {
        HashMap<String, String> parms = (HashMap<String, String>) lookupForm.getInitialRequestParameters();
        parms.remove(UifParameters.RETURN_FORM_KEY);

        //add an error message to display to the user
        redirectAttributes.mergeAttributes(parms);
        redirectAttributes.addAttribute(UifParameters.MESSAGE_TO_DISPLAY,
                RiceKeyConstants.INFO_LOOKUP_RESULTS_MV_RETURN_EXCEEDS_LIMIT);

        String formKeyParam = request.getParameter(UifParameters.FORM_KEY);
        redirectAttributes.addAttribute(UifParameters.FORM_KEY, formKeyParam);

        return UifConstants.REDIRECT_PREFIX + lookupForm.getRequestUrl();
    }

    if (redirectUrl.length() < RiceConstants.MAXIMUM_URL_LENGTH) {
        redirectAttributes.addAttribute(UifParameters.SELECTED_LINE_VALUES, selectedLineValues);
    }

    redirectAttributes.addAttribute(KRADConstants.DISPATCH_REQUEST_PARAMETER,
            KRADConstants.RETURN_METHOD_TO_CALL);

    if (StringUtils.isNotBlank(lookupForm.getReturnFormKey())) {
        redirectAttributes.addAttribute(UifParameters.FORM_KEY, lookupForm.getReturnFormKey());
    }

    redirectAttributes.addAttribute(KRADConstants.REFRESH_CALLER, lookupForm.getView().getId());
    redirectAttributes.addAttribute(KRADConstants.REFRESH_CALLER_TYPE,
            UifConstants.RefreshCallerTypes.MULTI_VALUE_LOOKUP);
    redirectAttributes.addAttribute(KRADConstants.REFRESH_DATA_OBJECT_CLASS,
            lookupForm.getDataObjectClassName());

    if (StringUtils.isNotBlank(lookupForm.getDocNum())) {
        redirectAttributes.addAttribute(UifParameters.DOC_NUM, lookupForm.getDocNum());
    }

    if (StringUtils.isNotBlank(lookupForm.getLookupCollectionName())) {
        redirectAttributes.addAttribute(UifParameters.LOOKUP_COLLECTION_NAME,
                lookupForm.getLookupCollectionName());
    }

    if (StringUtils.isNotBlank(lookupForm.getReferencesToRefresh())) {
        redirectAttributes.addAttribute(KRADConstants.REFERENCES_TO_REFRESH,
                lookupForm.getReferencesToRefresh());
    }

    // clear current form from session
    GlobalVariables.getUifFormManager().removeSessionForm(lookupForm);

    return UifConstants.REDIRECT_PREFIX + lookupForm.getReturnLocation();
}

From source file:org.kuali.student.common.uif.controller.KSLookupController.java

@RequestMapping(method = RequestMethod.POST, params = "methodToCall=returnSelected")
@Override// ww w.j av a 2  s  .  c o m
public String returnSelected(@ModelAttribute(UifConstants.KUALI_FORM_ATTR) LookupForm lookupForm,
        HttpServletRequest request, final RedirectAttributes redirectAttributes) {

    LookupUtils.refreshLookupResultSelections((LookupForm) lookupForm);

    // build string of select line fields
    String multiValueReturnFieldsParam = "";
    List<String> multiValueReturnFields = lookupForm.getMultiValueReturnFields();
    Collections.sort(multiValueReturnFields);
    if (multiValueReturnFields != null && !multiValueReturnFields.isEmpty()) {
        for (String field : multiValueReturnFields) {
            multiValueReturnFieldsParam += field + ",";
        }

        multiValueReturnFieldsParam = StringUtils.removeEnd(multiValueReturnFieldsParam, ",");

    }

    // build string of select line identifiers
    String selectedLineValues = "";
    Set<String> selectedLines = lookupForm.getSelectedCollectionLines().get(UifPropertyPaths.LOOKUP_RESULTS);
    if (selectedLines != null) {
        for (String selectedLine : selectedLines) {
            selectedLineValues += selectedLine.replaceAll(",", "&#44;").replaceAll(":", "&#58;") + ",";
        }
        selectedLineValues = StringUtils.removeEnd(selectedLineValues, ",");

    }

    Properties parameters = new Properties();
    parameters.put(UifParameters.SELECTED_LINE_VALUES, selectedLineValues);
    parameters.putAll(lookupForm.getInitialRequestParameters());

    String redirectUrl = UrlFactory.parameterizeUrl(lookupForm.getReturnLocation(), parameters);

    boolean lookupCameFromDifferentServer = KRADUtils.areDifferentDomains(lookupForm.getReturnLocation(),
            lookupForm.getRequestUrl());

    if (StringUtils.isNotBlank(multiValueReturnFieldsParam)) {
        redirectAttributes.addAttribute(UifParameters.MULIT_VALUE_RETURN_FILEDS, multiValueReturnFieldsParam);
    }

    if (redirectUrl.length() > RiceConstants.MAXIMUM_URL_LENGTH && !lookupCameFromDifferentServer) {
        redirectAttributes.addFlashAttribute(UifParameters.SELECTED_LINE_VALUES, selectedLineValues);
    }
    if (redirectUrl.length() > RiceConstants.MAXIMUM_URL_LENGTH && lookupCameFromDifferentServer) {
        Map<String, String[]> parms = lookupForm.getInitialRequestParameters();
        parms.remove(UifParameters.RETURN_FORM_KEY);

        //add an error message to display to the user
        redirectAttributes.mergeAttributes(parms);
        redirectAttributes.addAttribute(UifParameters.MESSAGE_TO_DISPLAY,
                RiceKeyConstants.INFO_LOOKUP_RESULTS_MV_RETURN_EXCEEDS_LIMIT);

        String formKeyParam = request.getParameter(UifParameters.FORM_KEY);
        redirectAttributes.addAttribute(UifParameters.FORM_KEY, formKeyParam);

        return UifConstants.REDIRECT_PREFIX + lookupForm.getRequestUrl();
    }

    if (redirectUrl.length() < RiceConstants.MAXIMUM_URL_LENGTH) {
        redirectAttributes.addAttribute(UifParameters.SELECTED_LINE_VALUES, selectedLineValues);
    }

    redirectAttributes.addAttribute(KRADConstants.DISPATCH_REQUEST_PARAMETER,
            KRADConstants.RETURN_METHOD_TO_CALL);

    if (StringUtils.isNotBlank(lookupForm.getReturnFormKey())) {
        redirectAttributes.addAttribute(UifParameters.FORM_KEY, lookupForm.getReturnFormKey());
    }

    redirectAttributes.addAttribute(KRADConstants.REFRESH_CALLER, lookupForm.getView().getId());
    redirectAttributes.addAttribute(KRADConstants.REFRESH_CALLER_TYPE,
            UifConstants.RefreshCallerTypes.MULTI_VALUE_LOOKUP);
    redirectAttributes.addAttribute(KRADConstants.REFRESH_DATA_OBJECT_CLASS,
            lookupForm.getDataObjectClassName());

    if (StringUtils.isNotBlank(lookupForm.getQuickfinderId())) {
        redirectAttributes.addAttribute(UifParameters.QUICKFINDER_ID, lookupForm.getQuickfinderId());
    }

    if (StringUtils.isNotBlank(lookupForm.getLookupCollectionName())) {
        redirectAttributes.addAttribute(UifParameters.LOOKUP_COLLECTION_NAME,
                lookupForm.getLookupCollectionName());
    }

    if (StringUtils.isNotBlank(lookupForm.getLookupCollectionId())) {
        redirectAttributes.addAttribute(UifParameters.LOOKUP_COLLECTION_ID, lookupForm.getLookupCollectionId());
    }

    if (StringUtils.isNotBlank(lookupForm.getReferencesToRefresh())) {
        redirectAttributes.addAttribute(KRADConstants.REFERENCES_TO_REFRESH,
                lookupForm.getReferencesToRefresh());
    }

    // clear current form from session
    GlobalVariables.getUifFormManager().removeSessionForm(lookupForm);

    return UifConstants.REDIRECT_PREFIX + lookupForm.getReturnLocation();
}

From source file:sg.ncl.MainController.java

private String checkUserStatus(@Valid @ModelAttribute("loginForm") LoginForm loginForm, HttpSession session,
        RedirectAttributes redirectAttributes, String token, String id, String role) {
    User2 user = invokeAndExtractUserInfo(id);

    try {//  w  w  w. j a v a  2s . com
        String userStatus = user.getStatus();
        boolean emailVerified = user.getEmailVerified();

        if (UserStatus.FROZEN.toString().equals(userStatus)) {
            log.warn("User {} login failed: account has been frozen", id);
            loginForm.setErrorMsg("Login Failed: Account Frozen. Please contact " + CONTACT_EMAIL);
            return LOGIN_PAGE;
        } else if (!emailVerified || (UserStatus.CREATED.toString()).equals(userStatus)) {
            redirectAttributes.addAttribute("statuschecklist", userStatus);
            log.info("User {} not validated, redirected to email verification page", id);
            return "redirect:/email_checklist";
        } else if ((UserStatus.PENDING.toString()).equals(userStatus)) {
            redirectAttributes.addAttribute("statuschecklist", userStatus);
            log.info("User {} not approved, redirected to application pending page", id);
            return "redirect:/email_checklist";
        } else if ((UserStatus.APPROVED.toString()).equals(userStatus)) {
            // set session variables
            setSessionVariables(session, loginForm.getLoginEmail(), id, user.getFirstName(), role, token);
            log.info("login success for {}, id: {}", loginForm.getLoginEmail(), id);
            return "redirect:/dashboard";
        } else {
            log.warn("login failed for user {}: account is rejected or closed", id);
            loginForm.setErrorMsg("Login Failed: Account Rejected/Closed.");
            return LOGIN_PAGE;
        }
    } catch (Exception e) {
        log.warn("Error parsing json object for user: {}", e.getMessage());
        loginForm.setErrorMsg(ERR_SERVER_OVERLOAD);
        return LOGIN_PAGE;
    }
}