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:com.manydesigns.portofino.dispatcher.DispatcherUtil.java

public static Dispatcher install(HttpServletRequest request) {
    ServletContext servletContext = ElementsThreadLocals.getServletContext();
    Configuration configuration = (Configuration) servletContext
            .getAttribute(BaseModule.PORTOFINO_CONFIGURATION);
    File pagesDir = (File) servletContext.getAttribute(PageactionsModule.PAGES_DIRECTORY);

    Dispatcher dispatcher = new Dispatcher(configuration, pagesDir);
    request.setAttribute(RequestAttributes.DISPATCHER, dispatcher);
    return dispatcher;
}

From source file:net.sourceforge.vulcan.web.struts.actions.BaseDispatchAction.java

protected final static void addMessage(HttpServletRequest request, String messagesKey, String propertyName,
        ActionMessage message) {/*from   w  ww . ja va2  s .c  o m*/
    ActionMessages msgs = (ActionMessages) request.getAttribute(messagesKey);
    if (msgs == null) {
        msgs = new ActionMessages();
    }
    msgs.add(propertyName, message);
    request.setAttribute(messagesKey, msgs);
}

From source file:ste.web.beanshell.jetty.BeanShellUtils.java

/**
 * Sets all variables available in the interpreter as request attributes.
 *
 * @param i the interpreter - NOT NULL//from  www.j a  v  a2 s .co  m
 * @param r - the request - NOT NULL
 *
 * @throws EvalError
 */
public static void setVariablesAttributes(final Interpreter i, final HttpServletRequest r) throws EvalError {
    if (i == null) {
        throw new IllegalArgumentException("i cannot be null");
    }

    if (r == null) {
        throw new IllegalArgumentException("r cannot be null");
    }

    String[] vars = (String[]) i.get("this.variables");
    for (String var : vars) {
        r.setAttribute(var, i.get(var));
    }
}

From source file:io.lavagna.web.helper.UserSession.java

static UserWithPermission fetchFromRequest(HttpServletRequest request, UserService userService) {

    Object userAttr = request.getAttribute(UserWithPermission.class.getName());

    if (userAttr != null) {
        return (UserWithPermission) userAttr;
    } else {//from  w  w  w.j av a 2 s.com
        UserWithPermission res = userService.findUserWithPermission(getUserId(request));
        request.setAttribute(UserWithPermission.class.getName(), res);
        return res;
    }
}

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

private static void setCommandGroups(HttpServletRequest req) {
    List groups = MonitoringFactory.loadAllCommandGroups();
    ArrayList lv = new ArrayList();
    CollectionUtils.collect(groups, new CommandGroupToLVBean(), lv);
    Collections.sort(lv, LabelValueBean.CASE_INSENSITIVE_ORDER);
    req.setAttribute("commandGroups", lv);
}

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

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

    if ("insert".equals(action)) {
        /** bind command */
        BindingResult res = val.bindAndValidate(command, req);
        if (res.hasErrors()) {
            //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 {
            service.insert(command);
            String server = RequestUtils.getFullServerPathHttp(req);
            //TODO set groups for getting advertisment from DB
            service.sendInsertNotificationUser(command, server, "site name", null);
            req.setAttribute(config.getContentDataAttribute(), service.getInsertBean());
            common.CommonAttributes.addHelpMessage("operation_succeed", req);
            //return true;
        }
    } else {
        req.setAttribute(config.getContentDataAttribute(), command);
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.controller.PostEditCleanupController.java

/**
 * Adds a attribute to the request to indicate which predicate was edited.
 * This attribute is used by some controllers to send the browser to the
 * place on the page relevant to the predicate.
 * /*from w w  w  .  j  a v  a2s.c o m*/
 * Never returns null, it will return an empty string if there is nothing. 
 */
public static String getPredicateAnchor(HttpServletRequest req, EditConfigurationVTwo config) {
    if (req == null || config == null)
        return "";

    //Get prop local name if it exists
    String predicateLocalName = Utilities.getPredicateLocalName(config);

    if (predicateLocalName != null && predicateLocalName.length() > 0) {
        String predicateAnchor = "#" + predicateLocalName;
        req.setAttribute("predicateAnchor", predicateAnchor);
        return predicateAnchor;
    } else {
        return "";
    }
}

From source file:com.benfante.taglib.frontend.utils.FlashHelper.java

public static void doSet(HttpServletRequest req, String code, String type, String attribute) {
    Map<String, String> flash = (Map<String, String>) req.getAttribute(attribute);
    if (flash == null)
        flash = new HashMap<String, String>();
    if (type == null) {
        type = DEFAULT_ERROR_TYPE;/*from  www. j ava2 s  . c  o  m*/
    }
    if (attribute == null) {
        attribute = DEFAULT_FLASH_ATTRIBUTE;
    }
    flash.put(type, code);
    req.setAttribute(attribute, flash);
}

From source file:org.hdiv.util.HDIVUtil.java

/**
 * Set the <code>IDataComposer</code>
 * /*from w ww.  j av a 2 s  .co m*/
 * @param newDataComposer
 *            new {@link IDataComposer}
 * @param request
 *            {@link HttpServletRequest} instance
 */
public static void setDataComposer(IDataComposer newDataComposer, HttpServletRequest request) {

    request.setAttribute(DATACOMPOSER_REQUEST_KEY, newDataComposer);

}

From source file:org.hdiv.util.HDIVUtil.java

/**
 * Set the RequestURI/*from  www  . j  a va2s. c  om*/
 * 
 * @param requestURI
 *            RequestURI to set
 * @param request
 *            {@link HttpServletRequest} object
 */
public static void setRequestURI(String requestURI, HttpServletRequest request) {

    request.setAttribute(REQUESTURI_REQUEST_KEY, requestURI);

}