Java Code Examples for javax.servlet.jsp.PageContext#setAttribute()

The following examples show how to use javax.servlet.jsp.PageContext#setAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScopedAttributeELResolver.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void setValue(ELContext context, Object base, Object property,
        Object value) throws NullPointerException,
        PropertyNotFoundException, PropertyNotWritableException,
        ELException {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null) {
        context.setPropertyResolved(true);
        if (property != null) {
            String key = property.toString();
            PageContext page = (PageContext) context
                    .getContext(JspContext.class);
            int scope = page.getAttributesScope(key);
            if (scope != 0) {
                page.setAttribute(key, value, scope);
            } else {
                page.setAttribute(key, value);
            }
        }
    }
}
 
Example 2
Source File: StoreTag.java    From JspMyAdmin2 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void doTag() throws JspException {
	PageContext pageContext = (PageContext) super.getJspContext();
	MessageReader messageReader = (MessageReader) pageContext
			.getAttribute(Constants.PAGE_CONTEXT_MESSAGES);
	Object temp = null;
	if (scope == null) {
		key = messageReader.getMessage(key);
		pageContext.setAttribute(name, key, PageContext.PAGE_SCOPE);
		return;
	} else if (Constants.COMMAND.equals(scope)) {
		temp = pageContext.getRequest().getAttribute(
				Constants.COMMAND);
		temp = super.getReflectValue(temp, key);
	} else if (Constants.PAGE.equals(scope)) {
		temp = pageContext.getAttribute(key);
	} else if (Constants.REQUEST.equals(scope)) {
		temp = pageContext.getRequest().getAttribute(key);
	}
	if (temp != null) {
		key = messageReader.getMessage(temp.toString());
		if (key != null) {
			pageContext.setAttribute(name, key, PageContext.PAGE_SCOPE);
		}
	}
}
 
Example 3
Source File: ScopedAttributeELResolver.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void setValue(ELContext context, Object base, Object property,
        Object value) throws NullPointerException,
        PropertyNotFoundException, PropertyNotWritableException,
        ELException {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null) {
        context.setPropertyResolved(true);
        if (property != null) {
            String key = property.toString();
            PageContext page = (PageContext) context
                    .getContext(JspContext.class);
            int scope = page.getAttributesScope(key);
            if (scope != 0) {
                page.setAttribute(key, value, scope);
            } else {
                page.setAttribute(key, value);
            }
        }
    }
}
 
Example 4
Source File: MessageOpenTag.java    From JspMyAdmin2 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void doTag() throws JspException {
	PageContext pageContext = (PageContext) super.getJspContext();
	HttpSession httpSession = pageContext.getSession();
	MessageReader messageReader = null;
	if (httpSession != null) {
		Object temp = httpSession
				.getAttribute(Constants.SESSION_LOCALE);
		if (temp != null) {
			messageReader = new MessageReader(temp.toString());
		} else {
			messageReader = new MessageReader(null);
		}
	} else {
		messageReader = new MessageReader(null);
	}
	pageContext.setAttribute(Constants.PAGE_CONTEXT_MESSAGES,
			messageReader, PageContext.PAGE_SCOPE);
}
 
Example 5
Source File: FrameworkUtils.java    From ontopia with Apache License 2.0 6 votes vote down vote up
/**
 * INTERNAL: Create new user object in given scope.
 */
public static UserIF createUserSession(PageContext pageContext, int scope) {

  NavigatorConfigurationIF navConf = NavigatorUtils.getNavigatorApplication(pageContext).getConfiguration();
  // try to retrieve the user name from the request, otherwise null
  String username = null;
  if (pageContext.getRequest() instanceof HttpServletRequest)
    username = ((HttpServletRequest) pageContext.getRequest()).getRemoteUser();
  // create new user object
  UserIF user = new User(username, navConf);
  // set MVS settings
  user = setDefaultMVS(navConf, user);
  // set user object to session scope
  pageContext.setAttribute(NavigatorApplicationIF.USER_KEY, user, scope);
  log.debug("New user object ('" + user.getId() + "') created and bound in scope ( " + scope + ").");
  return user;
}
 
Example 6
Source File: PageNavigationTag.java    From sinavi-jfw with Apache License 2.0 6 votes vote down vote up
private String invokeFragmentIfNeeded(
        JspFragment fragment,
        String defaultValue,
        int currentIndex) throws JspException {
    PageContext p = pageContext;
    StringWriter w = new StringWriter();
    if (fragment != null) {
        if (currentIndex > 0) p.setAttribute(var, currentIndex);
        try {
            fragment.invoke(w);
        } catch (IOException e) {throw new JspException(e);}
        if (currentIndex > 0) p.removeAttribute(var);
    } else {
        w.append(Strings.substitute(
                defaultValue,
                Maps.hash(var, String.valueOf(currentIndex))));
    }
    return w.toString();
}
 
Example 7
Source File: StatusWorker.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
public static void getStatusItems(PageContext pageContext, String attributeName, String statusTypeId) {
    Delegator delegator = (Delegator) pageContext.getRequest().getAttribute("delegator");

    try {
        List<GenericValue> statusItems = EntityQuery.use(delegator)
                                                    .from("StatusItem")
                                                    .where("statusTypeId", statusTypeId)
                                                    .orderBy("sequenceId")
                                                    .cache(true)
                                                    .queryList();
        if (statusItems != null)
            pageContext.setAttribute(attributeName, statusItems);
    } catch (GenericEntityException e) {
        Debug.logError(e, module);
    }
}
 
Example 8
Source File: Utils.java    From ontopia with Apache License 2.0 5 votes vote down vote up
/**
 * INTERNAL: Helper method for maintaining a relation mapping
 * instance throughout a page context.
 */  
public static RelationMapping getRelationMapping(PageContext ctxt) {
  RelationMapping db = (RelationMapping)
    ctxt.getAttribute("RelationMapping", PageContext.APPLICATION_SCOPE);
  if (db == null) {
    db = new RelationMapping();
    ctxt.setAttribute("RelationMapping", db, PageContext.APPLICATION_SCOPE);
  }
  return db;
}
 
Example 9
Source File: FrameworkUtils.java    From ontopia with Apache License 2.0 5 votes vote down vote up
/**
 * INTERNAL: Reset MVS settings in user object in session scope.
 */
public static void resetMVSsettingsInUserSession(PageContext pageContext) {
  NavigatorConfigurationIF navConf = NavigatorUtils.getNavigatorApplication(pageContext).getConfiguration();

  //! UserIF user = (UserIF) pageContext.getAttribute(NavigatorApplicationIF.USER_KEY,
  //!                                                 PageContext.SESSION_SCOPE);
  UserIF user = getUser(pageContext, false);
  if (user == null) return; // ignore if no user

  // reset MVS settings
  user = setDefaultMVS(navConf, user);
  // set user object to session scope (TODO: support other contexts?)
  pageContext.setAttribute(NavigatorApplicationIF.USER_KEY, user, PageContext.SESSION_SCOPE);
  log.info("MVS settings in user session has been reset.");
}
 
Example 10
Source File: ImplicitObjectELResolver.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public static ScopeManager get(PageContext page) {
    ScopeManager mngr = (ScopeManager) page.getAttribute(MNGR_KEY);
    if (mngr == null) {
        mngr = new ScopeManager(page);
        page.setAttribute(MNGR_KEY, mngr);
    }
    return mngr;
}
 
Example 11
Source File: TagIdGenerator.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Get the next unique ID (within the given {@link PageContext}) for the supplied name.
 */
public static String nextId(String name, PageContext pageContext) {
	String attributeName = PAGE_CONTEXT_ATTRIBUTE_PREFIX + name;
	Integer currentCount = (Integer) pageContext.getAttribute(attributeName);
	currentCount = (currentCount != null ? currentCount + 1 : 1);
	pageContext.setAttribute(attributeName, currentCount);
	return (name + currentCount);
}
 
Example 12
Source File: ImplicitObjectELResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * Finds the ImplicitObjects associated with the PageContext,
 * creating it if it doesn't yet exist.
 **/
public static ImplicitObjects getImplicitObjects (PageContext pContext)
{
  ImplicitObjects objs = 
    (ImplicitObjects)
    pContext.getAttribute (sAttributeName,
                           PageContext.PAGE_SCOPE);
  if (objs == null) {
    objs = new ImplicitObjects (pContext);
    pContext.setAttribute (sAttributeName,
                           objs,
                           PageContext.PAGE_SCOPE);
  }
  return objs;
}
 
Example 13
Source File: TagIdGenerator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the next unique ID (within the given {@link PageContext}) for the supplied name.
 */
public static String nextId(String name, PageContext pageContext) {
	String attributeName = PAGE_CONTEXT_ATTRIBUTE_PREFIX + name;
	Integer currentCount = (Integer) pageContext.getAttribute(attributeName);
	currentCount = (currentCount != null ? currentCount + 1 : 1);
	pageContext.setAttribute(attributeName, currentCount);
	return (name + currentCount);
}
 
Example 14
Source File: ImplicitObjectELResolver.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public static ScopeManager get(PageContext page) {
    ScopeManager mngr = (ScopeManager) page.getAttribute(MNGR_KEY);
    if (mngr == null) {
        mngr = new ScopeManager(page);
        page.setAttribute(MNGR_KEY, mngr);
    }
    return mngr;
}
 
Example 15
Source File: TagIdGenerator.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Get the next unique ID (within the given {@link PageContext}) for the supplied name.
 */
public static String nextId(String name, PageContext pageContext) {
	String attributeName = PAGE_CONTEXT_ATTRIBUTE_PREFIX + name;
	Integer currentCount = (Integer) pageContext.getAttribute(attributeName);
	currentCount = (currentCount != null ? currentCount + 1 : 1);
	pageContext.setAttribute(attributeName, currentCount);
	return (name + currentCount);
}
 
Example 16
Source File: TagIdGenerator.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Get the next unique ID (within the given {@link PageContext}) for the supplied name.
 */
public static String nextId(String name, PageContext pageContext) {
	String attributeName = PAGE_CONTEXT_ATTRIBUTE_PREFIX + name;
	Integer currentCount = (Integer) pageContext.getAttribute(attributeName);
	currentCount = (currentCount != null ? currentCount + 1 : 1);
	pageContext.setAttribute(attributeName, currentCount);
	return (name + currentCount);
}
 
Example 17
Source File: ImplicitObjectELResolver.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public static ScopeManager get(PageContext page) {
    ScopeManager mngr = (ScopeManager) page.getAttribute(MNGR_KEY);
    if (mngr == null) {
        mngr = new ScopeManager(page);
        page.setAttribute(MNGR_KEY, mngr);
    }
    return mngr;
}
 
Example 18
Source File: TagUtils.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
static void setDefaultLogger(final PageContext pageContext, final Log4jTaglibLogger logger) {
    pageContext.setAttribute(TagUtils.LOGGER_SCOPE_ATTRIBUTE, logger, PageContext.PAGE_SCOPE);
}
 
Example 19
Source File: ScopedAttributeELResolver.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * If the base object is <code>null</code>, sets an existing scoped
 * attribute to the new value, or creates a new scoped attribute if one
 * does not exist by this name.
 *
 * <p>If the provided attribute name matches the key of an attribute 
 * in page scope, request scope, session scope, or application scope, the 
 * corresponding attribute value will be replaced by the provided value.
 * Otherwise, a new page scope attribute will be created with the
 * given name and value.</p>
 *
 * <p>The <code>propertyResolved</code> property of the 
 * <code>ELContext</code> object must be set to <code>true</code> by 
 * this resolver before returning if base is <code>null</code>. If 
 * this property is not <code>true</code> after this method is called,
 * the caller should ignore the return value.</p>
 *
 * @param context The context of this evaluation.
 * @param base Only <code>null</code> is handled by this resolver.
 *     Other values will result in an immediate return.
 * @param property The name of the scoped attribute to set.
 * @param val The value for the scoped attribute.
 * @throws NullPointerException if context is <code>null</code>.
 * @throws ELException if an exception was thrown while performing
 *     the property or variable resolution. The thrown exception
 *     must be included as the cause property of this exception, if
 *     available.
 */
public void  setValue(ELContext context,
                      Object base,
                      Object property,
                      Object val) {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null) {
        context.setPropertyResolved(true);
        if (property instanceof String) {
            PageContext ctxt = (PageContext)
                                   context.getContext(JspContext.class);
            String attr = (String) property;
            if (ctxt.getAttribute(attr, PageContext.REQUEST_SCOPE) != null)
                ctxt.setAttribute(attr, val, PageContext.REQUEST_SCOPE);
            else if (ctxt.getAttribute(attr, PageContext.SESSION_SCOPE) != null)
                ctxt.setAttribute(attr, val, PageContext.SESSION_SCOPE);
            else if (ctxt.getAttribute(attr, PageContext.APPLICATION_SCOPE) != null)
                ctxt.setAttribute(attr, val, PageContext.APPLICATION_SCOPE);
            else {
                ctxt.setAttribute(attr, val, PageContext.PAGE_SCOPE);
            }
        }
    }
}
 
Example 20
Source File: ListTagUtil.java    From spacewalk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Stores a ListCommand in the page context and makes it current
 * @param ctx caller's page context
 * @param uniqueName owning list's unique name
 * @param cmd new current command
 */
public static void setCurrentCommand(PageContext ctx, String uniqueName,
        ListCommand cmd) {
    ctx.setAttribute(uniqueName + "_cmd", cmd);
}