List of usage examples for javax.servlet.jsp PageContext REQUEST_SCOPE
int REQUEST_SCOPE
To view the source code for javax.servlet.jsp PageContext REQUEST_SCOPE.
Click Source Link
From source file:org.apache.struts.taglib.TestTagUtils.java
public void testMessageApplicationGoodKeyWithParams() { putBundleInScope(PageContext.REQUEST_SCOPE, true); String[] args = { "I love this" }; String val = null; try {//from w w w.j ava 2 s.co m val = tagutils.message(pageContext, null, null, "foo.bar", args); assertTrue("Validate message value", "I love this bar".equals(val)); } catch (JspException e) { fail("val should be \"bar\""); } }
From source file:org.apache.struts.taglib.TestTagUtils.java
public void testPresentBadKey() { putBundleInScope(PageContext.REQUEST_SCOPE, true); boolean result = false; try {//from www .j av a 2 s .com result = tagutils.present(pageContext, null, null, "foo.bar.not.exist"); assertFalse("Value should be null", result); } catch (JspException e) { fail("An npe should have been thrown"); } catch (NullPointerException e) { assertFalse("Correct behaviour", result); } }
From source file:org.apache.struts.taglib.TestTagUtils.java
public void testPresentGoodKey() { putBundleInScope(PageContext.REQUEST_SCOPE, true); boolean result = false; try {//from w ww . j a v a 2 s.com result = tagutils.present(pageContext, null, null, "foo"); assertTrue("Key should have been found", result); } catch (JspException e) { fail("An exception should have been thrown"); } }
From source file:org.apache.struts.taglib.tiles.InsertTag.java
/** * Get current component context.// w w w . j ava 2 s. c o m */ private ComponentContext getCurrentContext() { if (cachedCurrentContext == null) { cachedCurrentContext = (ComponentContext) pageContext.getAttribute(ComponentConstants.COMPONENT_CONTEXT, PageContext.REQUEST_SCOPE); } return cachedCurrentContext; }
From source file:org.apache.struts.taglib.tiles.InsertTag.java
/** * Process tag attribute "definition".// w ww . java 2s. c o m * First, search definition in the factory, then create handler from this definition. * @param name Name of the definition. * @return Appropriate TagHandler. * @throws JspException- NoSuchDefinitionException No Definition found for name. * @throws JspException- FactoryNotFoundException Can't find Definitions factory. * @throws JspException- DefinedComponentFactoryException General error in factory. * @throws JspException InstantiationException Can't create requested controller */ protected TagHandler processDefinitionName(String name) throws JspException { try { ComponentDefinition definition = TilesUtil.getDefinition(name, (HttpServletRequest) pageContext.getRequest(), pageContext.getServletContext()); if (definition == null) { // is it possible ? throw new NoSuchDefinitionException(); } return processDefinition(definition); } catch (NoSuchDefinitionException ex) { throw new JspException("Error - Tag Insert : Can't get definition '" + definitionName + "'. Check if this name exist in definitions factory."); } catch (FactoryNotFoundException ex) { throw new JspException(ex.getMessage()); } catch (DefinitionsFactoryException ex) { if (log.isDebugEnabled()) { ex.printStackTrace(); } // Save exception to be able to show it later pageContext.setAttribute(Globals.EXCEPTION_KEY, ex, PageContext.REQUEST_SCOPE); throw new JspException(ex.getMessage()); } }
From source file:org.apache.struts.taglib.tiles.util.TagUtils.java
/** * Store bean in requested context./* w w w .java 2 s. c o m*/ * If scope is <code>null</code>, save it in REQUEST_SCOPE context. * * @param pageContext Current pageContext. * @param name Name of the bean. * @param scope Scope under which bean is saved (page, request, session, application) * or <code>null</code> to store in <code>request()</code> instead. * @param value Bean value to store. * * @exception JspException Scope name is not recognized as a valid scope */ public static void setAttribute(PageContext pageContext, String name, Object value, String scope) throws JspException { if (scope == null) pageContext.setAttribute(name, value, PageContext.REQUEST_SCOPE); else if (scope.equalsIgnoreCase("page")) pageContext.setAttribute(name, value, PageContext.PAGE_SCOPE); else if (scope.equalsIgnoreCase("request")) pageContext.setAttribute(name, value, PageContext.REQUEST_SCOPE); else if (scope.equalsIgnoreCase("session")) pageContext.setAttribute(name, value, PageContext.SESSION_SCOPE); else if (scope.equalsIgnoreCase("application")) pageContext.setAttribute(name, value, PageContext.APPLICATION_SCOPE); else { throw new JspException("Error - bad scope name '" + scope + "'"); } }
From source file:org.apache.struts.taglib.tiles.util.TagUtils.java
/** * Store bean in REQUEST_SCOPE context.//from w w w . jav a 2 s . c o m * * @param pageContext Current pageContext. * @param name Name of the bean. * @param beanValue Bean value to store. * * @exception JspException Scope name is not recognized as a valid scope */ public static void setAttribute(PageContext pageContext, String name, Object beanValue) throws JspException { pageContext.setAttribute(name, beanValue, PageContext.REQUEST_SCOPE); }
From source file:org.apache.struts.taglib.tiles.util.TagUtils.java
/** * Save the specified exception as a request attribute for later use. * * @param pageContext The PageContext for the current page. * @param exception The exception to be saved. *//*from www .j a v a 2s.c o m*/ public static void saveException(PageContext pageContext, Throwable exception) { pageContext.setAttribute(Globals.EXCEPTION_KEY, exception, PageContext.REQUEST_SCOPE); }
From source file:org.apache.struts.tiles.taglib.InsertTag.java
/** * Process tag attribute "definition"./*w ww . j av a 2 s . c o m*/ * First, search definition in the factory, then create handler from this definition. * @param name Name of the definition. * @return Appropriate TagHandler. * @throws JspException- NoSuchDefinitionException No Definition found for name. * @throws JspException- FactoryNotFoundException Can't find Definitions factory. * @throws JspException- DefinedComponentFactoryException General error in factory. * @throws JspException InstantiationException Can't create requested controller */ protected TagHandler processDefinitionName(String name) throws JspException { try { ComponentDefinition definition = TilesUtil.getDefinition(name, (HttpServletRequest) pageContext.getRequest(), pageContext.getServletContext()); if (definition == null) { // is it possible ? throw new NoSuchDefinitionException(); } return processDefinition(definition); } catch (NoSuchDefinitionException ex) { throw new JspException("Error - Tag Insert : Can't get definition '" + definitionName + "'. Check if this name exist in definitions factory.", ex); } catch (FactoryNotFoundException ex) { throw new JspException(ex.getMessage()); } catch (DefinitionsFactoryException ex) { if (log.isDebugEnabled()) { ex.printStackTrace(); } // Save exception to be able to show it later pageContext.setAttribute(Globals.EXCEPTION_KEY, ex, PageContext.REQUEST_SCOPE); throw new JspException(ex); } }
From source file:org.apache.taglib.tiles.InsertTag.java
/** * Process tag attribute "definition"./*from w w w. ja v a2s. c o m*/ * First, search definition in the factory, then create handler from this definition. * @param name Name of the definition. * @return Appropriate TagHandler. * @throws JspException- NoSuchDefinitionException No Definition found for name. * @throws JspException- FactoryNotFoundException Can't find Definitions factory. * @throws JspException- DefinedComponentFactoryException General error in factory. * @throws JspException InstantiationException Can't create requested controller */ protected TagHandler processDefinitionName(String name) throws JspException { try { ComponentDefinition definition = TilesUtil.getDefinition(name, (HttpServletRequest) pageContext.getRequest(), pageContext.getServletContext()); if (definition == null) { // is it possible ? throw new NoSuchDefinitionException(); } return processDefinition(definition); } catch (NoSuchDefinitionException ex) { throw new JspException("Error - Tag Insert : Can't get definition '" + definitionName + "'. Check if this name exist in definitions factory."); } catch (FactoryNotFoundException ex) { log.info("FACTORY NOT FOUND"); String msg = (String) pageContext.getServletContext().getAttribute(Globals.TILES_INIT_EXCEPTION); throw new JspException(msg); } catch (DefinitionsFactoryException ex) { log.info("DEFINITIONS FACTORY EXCEPTION"); if (log.isDebugEnabled()) { ex.printStackTrace(); } // Save exception to be able to show it later pageContext.setAttribute(Globals.EXCEPTION_KEY, ex, PageContext.REQUEST_SCOPE); throw new JspException(ex.getMessage()); } }