@Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); ServletContext servletContext = getServletContext(); Assert.state(servletContext != null, "No ServletContext"); this.applicationContext = ServletUtil.getApplicationContext(servletContext); if (this.renderer == null) { TilesContainer container = TilesAccess.getContainer(this.applicationContext); this.renderer = new DefinitionRenderer(container); } }
@Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); ServletContext servletContext = getServletContext(); Assert.state(servletContext != null, "No ServletContext"); this.applicationContext = ServletUtil.getApplicationContext(servletContext); if (this.renderer == null) { TilesContainer container = TilesAccess.getContainer(this.applicationContext); this.renderer = new DefinitionRenderer(container); } }
@Test public void simpleBootstrap() { MockServletContext servletContext = new MockServletContext(); TilesConfigurer tc = new TilesConfigurer(); tc.setDefinitions("/org/springframework/web/servlet/view/tiles3/tiles-definitions.xml"); tc.setCheckRefresh(true); tc.setServletContext(servletContext); tc.afterPropertiesSet(); ApplicationContext tilesContext = ServletUtil.getApplicationContext(servletContext); BasicTilesContainer container = (BasicTilesContainer) TilesAccess.getContainer(tilesContext); Request requestContext = new ServletRequest(container.getApplicationContext(), new MockHttpServletRequest(), new MockHttpServletResponse()); assertNotNull(container.getDefinitionsFactory().getDefinition("test", requestContext)); tc.destroy(); }
BasicTilesContainer container = (BasicTilesContainer) TilesAccess.getContainer(tilesAppContext);
/** * Returns default the container to be used in the application. * * @param context The Tiles application context object to use. * @return The default container object. * @since 3.0.0 */ public static TilesContainer getContainer(ApplicationContext context) { return getContainer(context, CONTAINER_ATTRIBUTE); }
protected TilesContainer initTilesContainer(ApplicationContext applicationContext, ServletRequest servletRequest) { TilesContainer container = TilesAccess.getContainer(applicationContext); TilesAccess.setCurrentContainer(servletRequest, container); return container; }
/** * Returns the current container that has been set, or the default one. * * @param request The request to use. * @return The current Tiles container to use in web pages. * @since 2.1.0 */ public static TilesContainer getCurrentContainer(Request request) { ApplicationContext context = request.getApplicationContext(); Map<String, Object> requestScope = request.getContext("request"); TilesContainer container = (TilesContainer) requestScope.get(CURRENT_CONTAINER_ATTRIBUTE_NAME); if (container == null) { container = getContainer(context); requestScope.put(CURRENT_CONTAINER_ATTRIBUTE_NAME, container); } return container; } }
/** * Returns the Tiles application context object. * * @param context The (application) context to use. * @return The required Tiles application context. * @deprecated Use one of the environment-specific Utilities (e.g. * ServletUtil). */ @Deprecated public static TilesApplicationContext getApplicationContext(Object context) { TilesContainer container = getContainer(context); if (container != null) { return container.getApplicationContext(); } return (TilesApplicationContext) getAttribute(context, CONTEXT_ATTRIBUTE); }
/** * By default, all ContainerTags evaluate their body. Subclasses may choose to be more selective. * In any case, children can rely upon the container and attributeContext being initialized if they * call <code>super.doStartTag()</code> * * @return <code>EVAL_BODY_BUFFERED</code>. * @throws TilesJspException If the container has not been initialized. */ public int doStartTag() throws TilesJspException { container = TilesAccess.getContainer(pageContext.getServletContext()); if (container != null) { startContext(pageContext); return EVAL_BODY_BUFFERED; } else { throw new TilesJspException("TilesContainer not initialized"); } }
/** * Sets the current container to use in web pages. * * @param request The request to use. * @param key The key under which the container is stored. * @since 2.1.0 */ public static void setCurrentContainer(Request request, String key) { ApplicationContext applicationContext = request.getApplicationContext(); TilesContainer container = getContainer(applicationContext, key); if (container != null) { request.getContext("request").put(CURRENT_CONTAINER_ATTRIBUTE_NAME, container); } else { throw new NoSuchContainerException("The container with the key '" + key + "' cannot be found"); } }
/** * * @param actionUrl url should be start with "/" * @param request HttpServletRequest * @param response HttpServletResponse * @throws Exception Exception */ public static void render(String actionUrl, HttpServletRequest request, HttpServletResponse response) throws Exception { TilesContainer container = TilesAccess.getContainer( request.getSession().getServletContext()); AttributeContext attributeContext = container.startContext(request, response); Attribute attr = new Attribute(actionUrl); attributeContext.putAttribute("body", attr); container.render("main.layout", request, response); container.endContext(request, response); }
@Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); this.applicationContext = ServletUtil.getApplicationContext(getServletContext()); if (this.renderer == null) { TilesContainer container = TilesAccess.getContainer(this.applicationContext); this.renderer = new DefinitionRenderer(container); } }
@Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); this.applicationContext = ServletUtil.getApplicationContext(getServletContext()); if (this.renderer == null) { TilesContainer container = TilesAccess.getContainer(this.applicationContext); this.renderer = new DefinitionRenderer(container); } }
/** {@inheritDoc} */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse res) { ApplicationContext applicationContext = org.apache.tiles.request.servlet.ServletUtil .getApplicationContext(getServletContext()); Request request = new ServletRequest(applicationContext, req, res); TilesContainer container = TilesAccess.getContainer(applicationContext, containerKey); mutator.mutate(container.getAttributeContext(request), req); String definition = getDefinitionName(req); if (log.isDebugEnabled()) { log.info("Dispatching to tile '" + definition + "'"); } container.render(definition, request); }
/** * {@inheritDoc} */ public void doFilter(javax.servlet.ServletRequest req, ServletResponse res, FilterChain filterChain) throws IOException, ServletException { // If the request contains the prevent token, we must not reapply the definition. // This is used to ensure that filters mapped to wild cards do not infinately // loop. if (!isPreventTokenPresent(req)) { ApplicationContext applicationContext = org.apache.tiles.request.servlet.ServletUtil .getApplicationContext(servletContext); Request request = new ServletRequest(applicationContext, (HttpServletRequest) req, (HttpServletResponse) res); TilesContainer container = TilesAccess.getContainer(applicationContext, containerKey); mutator.mutate(container.getAttributeContext(request), req); if (preventDecorationToken != null) { req.setAttribute(preventDecorationToken, Boolean.TRUE); } String definitionName = getDefinitionForRequest(req); container.render(definitionName, request); } filterChain.doFilter(req, res); }
private void initContainer(ExternalContext context) { if(TilesAccess.getContainer(context.getContext())==null) { try { TilesContainerFactory factory = TilesContainerFactory.getFactory(context.getContext()); TilesContainer container = factory.createTilesContainer(context.getContext()); TilesAccess.setContainer(context.getContext(),container); } catch (Exception e) { throw new FacesException("Error reading tiles definitions : " + e.getMessage(), e); } } }
protected void fallbackModelRenderer( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { Request tilesRequest = super.createTilesRequest(request, response); ApplicationContext applicationContext = tilesRequest.getApplicationContext(); TilesContainer container = TilesAccess.getContainer(applicationContext); if (container == null) { throw new ServletException("Tiles container is not initialized. " + "Have you added a TilesConfigurer to your web application context?"); } exposeModelAsRequestAttributes(model, request); JstlUtils.exposeLocalizationContext(new RequestContext(request, getServletContext())); Definition definition = container.getDefinition(getUrl(), tilesRequest); container.render(definition, tilesRequest); } }
public void testFlattenAttributeMap() throws Exception { ApplicationContext tilesAppContext = new WildcardServletApplicationContext(servletContext); Request tilesRequest = new ServletRequest(tilesAppContext, request, response); BasicTilesContainer container = (BasicTilesContainer) TilesAccess.getContainer(tilesAppContext); Definition compositeDefinition = container.getDefinitionsFactory().getDefinition("search", tilesRequest); Map<String, Attribute> resultMap = new HashMap<>(); ajaxTilesView.flattenAttributeMap(container, tilesRequest, resultMap, compositeDefinition); assertNotNull(resultMap.get("body")); assertNotNull(resultMap.get("searchForm")); assertEquals("/WEB-INF/searchForm.jsp", resultMap.get("searchForm").toString()); assertNotNull(resultMap.get("searchResults")); }
public void testRenderFragment_DynamicAttribute() throws Exception { ApplicationContext tilesAppContext = new WildcardServletApplicationContext(servletContext); Request tilesRequest = new ServletRequest(tilesAppContext, request, response); BasicTilesContainer container = (BasicTilesContainer) TilesAccess.getContainer(tilesAppContext); AttributeContext attributeContext = container.startContext(tilesRequest); attributeContext.putAttribute("body", new Attribute("/WEB-INF/dynamicTemplate.jsp")); Map<String, Attribute> resultMap = new HashMap<>(); ajaxTilesView.addRuntimeAttributes(container, tilesRequest, resultMap); assertNotNull(resultMap.get("body")); assertEquals("/WEB-INF/dynamicTemplate.jsp", resultMap.get("body").toString()); container.endContext(tilesRequest); }
public void testRenderFragment_InheritCascadedAttribute() throws Exception { ApplicationContext tilesAppContext = new WildcardServletApplicationContext(servletContext); Request tilesRequest = new ServletRequest(tilesAppContext, request, response); BasicTilesContainer container = (BasicTilesContainer) TilesAccess.getContainer(tilesAppContext); Definition definition = container.getDefinitionsFactory().getDefinition("search.body", tilesRequest); definition.setPreparer(AttributeTestingPreparer.class.getName()); setupStaticWebApplicationContext(); request.addHeader("Accept", DefaultAjaxHandler.AJAX_ACCEPT_CONTENT_TYPE); request.addParameter("fragments", "body"); ajaxTilesView.setUrl("search"); ajaxTilesView.afterPropertiesSet(); ajaxTilesView.renderMergedOutputModel(new HashMap<>(), request, response); assertTrue(AttributeTestingPreparer.invoked); }