Example usage for javax.servlet.http HttpServletRequest setAttribute

List of usage examples for javax.servlet.http HttpServletRequest setAttribute

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest setAttribute.

Prototype

public void setAttribute(String name, Object o);

Source Link

Document

Stores an attribute in this request.

Usage

From source file:common.web.controller.CommonActions.java

/**
 * executes an update, serves as a template method that incapsulates common logic for insert action
 * @param service/*from   w  ww . j  a v  a2 s . c  o m*/
 * @param config
 * @param val for validation
 * @param req resulting model (i.e. errors, command objects ...) will be placed here
 */
public static <T> boolean doInsert(IInsertService<T> service, IControllerConfig config, ABindValidator val,
        HttpServletRequest req) {
    String action = req.getParameter(ControllerConfig.ACTION_PARAM_NAME);
    T command = service.getInsertBean();
    RequestUtils.copyRequestAttributesFromMap(req, service.initInsert());

    if ("insert".equals(action)) {
        /** bind command */
        BindingResult res = val.bindAndValidate(command, req);
        if (res.hasErrors() || !service.insert(command)) {
            //m.putAll(res.getModel());
            req.setAttribute(res.MODEL_KEY_PREFIX + config.getContentDataAttribute(), res);
            req.setAttribute(config.getContentDataAttribute(), command);
            common.CommonAttributes.addErrorMessage("form_errors", req);
            return false;
        } else {
            //req.setAttribute(config.getContentDataAttribute(), service.getInsertBean());
            req.setAttribute(config.getContentDataAttribute(), command);
            common.CommonAttributes.addHelpMessage("operation_succeed", req);
        }
    } else {
        //val.bindAndValidate(command, req);
        req.setAttribute(config.getContentDataAttribute(), command);
    }
    return true;
}

From source file:com.runwaysdk.controller.ErrorUtility.java

public static void prepareMessages(HttpServletRequest req) {
    String errorMessage = req.getParameter(ErrorUtility.ERROR_MESSAGE);
    String errorMessageArray = req.getParameter(ErrorUtility.ERROR_MESSAGE_ARRAY);
    String compressedMessage = req.getParameter(ErrorUtility.MESSAGE_ARRAY);

    if (errorMessage != null) {
        req.setAttribute(ERROR_MESSAGE, errorMessage);
    }/*from   w ww.  j a  va 2s .c o  m*/

    if (errorMessageArray != null) {
        String[] array = errorMessageArray.split("\\n");

        req.setAttribute(ERROR_MESSAGE_ARRAY, array);
    }

    if (compressedMessage != null) {
        String message = ErrorUtility.decompress(compressedMessage);
        String[] array = message.split("\\n");

        req.setAttribute(MESSAGE_ARRAY, array);
    }
}

From source file:com.stratelia.silverpeas.pdcPeas.servlets.PdcSearchRequestRouterHelper.java

public static void processItemsPagination(String function, PdcSearchSessionController pdcSC,
        HttpServletRequest request) {
    String index = request.getParameter("Index");
    if (StringUtil.isDefined(index)) {
        pdcSC.setIndexOfFirstItemToDisplay(index);
    }/*from w w  w  .  j av  a2  s. c o  m*/
    request.setAttribute("NbItemsPerPage", Integer.valueOf(pdcSC.getNbItemsPerPage()));
    request.setAttribute("FirstItemIndex", Integer.valueOf(pdcSC.getIndexOfFirstItemToDisplay()));

    Value value = pdcSC.getCurrentValue();
    request.setAttribute("SelectedValue", value);
}

From source file:com.liusoft.dlog4j.action.ActionBase.java

/**
 * ????url?//  www .  ja  v a  2 s.c om
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @param msg
 * @param url
 * @return
 * @throws IOException 
 */
protected static ActionForward msgbox(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response, String msg, String url) throws IOException {
    if (StringUtils.isEmpty(url))
        return msgbox(mapping, form, request, response, msg);

    if (StringUtils.isNotEmpty(msg))
        request.setAttribute("msg", msg);
    if (StringUtils.isNotEmpty(url))
        request.setAttribute("page", url);

    return mapping.findForward("msgbox");
}

From source file:com.stratelia.silverpeas.pdcPeas.servlets.PdcSearchRequestRouterHelper.java

public static QueryParameters saveFavoriteRequestAndSetPdcInfo(PdcSearchSessionController pdcSC,
        HttpServletRequest request, String favoriteRequestId) throws Exception {
    // this parameter is for Back Button on result page
    String urlToRedirect = request.getParameter("urlToRedirect");
    request.setAttribute("urlToRedirect", urlToRedirect);
    // load settings of selected Interest center
    InterestCenter ic = pdcSC.loadICenter(favoriteRequestId);
    QueryParameters queryParameters = saveFavoriteRequest(pdcSC, ic);
    setUserChoices(request, pdcSC);/*from  w  ww  . j  av a  2  s  .  c  o  m*/
    setAttributesAdvancedSearch(pdcSC, request, true);
    setPertinentAxis(pdcSC, request);
    setContext(pdcSC, request);

    return queryParameters;
}

From source file:com.swiftcorp.portal.common.util.WebUtils.java

public static void setFailureMessages(HttpServletRequest request, String messageKey, String val) {
    if (messageKey == null || messageKey.length() == 0) {
        theLogger.error("messageKeys cant null or empty");
        throw new RuntimeException("messageKeys cant null or empty");
    }/* w  w  w.j a  v a 2  s  .  co  m*/

    ActionMessages actionMessages = new ActionMessages();
    ActionMessage actionMessage = new ActionMessage(messageKey, val);
    actionMessages.add(ActionMessages.GLOBAL_MESSAGE, actionMessage);
    request.setAttribute(Globals.ERROR_KEY, actionMessages);
}

From source file:com.swiftcorp.portal.common.util.WebUtils.java

public static void setFailureMessages(HttpServletRequest request, String messageKey, String val1, String val2) {
    if (messageKey == null || messageKey.length() == 0) {
        theLogger.error("messageKeys cant null or empty");
        throw new RuntimeException("messageKeys cant null or empty");
    }/*w  ww .j  a v  a  2  s. c o  m*/

    ActionMessages actionMessages = new ActionMessages();
    ActionMessage actionMessage = new ActionMessage(messageKey, val1, val2);
    actionMessages.add(ActionMessages.GLOBAL_MESSAGE, actionMessage);
    request.setAttribute(Globals.ERROR_KEY, actionMessages);
}

From source file:com.redhat.rhn.frontend.action.systems.monitoring.BaseProbeAction.java

/**
 * Get a list of the contact groups for <code>org</code>
 * as <code>LabelValueBeans</code>
 * @param orgIn the org for which to get the contact groups
 *///from   w  w  w  .  j a v a 2  s.c o m
protected static void setContactGroups(HttpServletRequest req, Org orgIn) {
    List rv = new LinkedList();
    Iterator i = orgIn.getContactGroups().iterator();
    while (i.hasNext()) {
        ContactGroup cg = (ContactGroup) i.next();
        rv.add(new LabelValueBean(cg.getContactGroupName(), cg.getId().toString()));
    }
    // Sort the list
    Collections.sort(rv);
    req.setAttribute("contactGroups", rv);
}

From source file:com.liusoft.dlog4j.action.ActionBase.java

/**
 * ??validateSiteOwner??//from  w  w  w. j a va 2 s  .c om
 * @param req
 * @return
 */
protected static SiteBean getSiteBean(HttpServletRequest req) {
    SiteBean site = (SiteBean) req.getAttribute(KEY_SITE);
    if (site == null) {
        try {
            int site_id = Integer.parseInt(req.getParameter(Globals.PARAM_SID));
            site = SiteDAO.getSiteByID(site_id);
            if (site != null)
                req.setAttribute(KEY_SITE, site);
        } catch (Exception e) {
        }
    }
    return site;
}

From source file:com.founder.fix.fixflow.explorer.util.FileHandle.java

public static void whenUploadFileBindParameter(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    try {/* w  w w  .  j  av a 2  s  .  c o m*/
        fi.clear();
        fi.removeAll(fi);
        Iterator<FileItem> iterator = createFactory(request, response);
        while (iterator.hasNext()) {
            FileItem fileItem = (FileItem) iterator.next();
            if (fileItem.isFormField()) { // ??????
                String name = fileItem.getFieldName(); // inputname
                String value = fileItem.getString(); // input?value
                request.setAttribute(filterEncoding(name), filterEncoding(value));
            } else {
                fi.add(fileItem);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Exception("??!");
    }
}