Announcement Announcement Module
Collapse
No announcement yet.
Spring, Tiles, MyFaces - Cannot forward after response... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring, Tiles, MyFaces - Cannot forward after response...

    Hi,

    I am trying to use tiles for a simple header, content, menue templating of my web application. I know that there already a few post in this forum concerning this problem, but I just couldn’t extract the “ultimate? solution for this. There are few people which switched to sitemesh or another templating system, but I would like to keep tiles.

    Main problem using tiles is that controllerClass definitions like:
    Code:
    <definition name="projectmanagement_list" extends="layout.example"  controllerClass="de.adtech.swd.frontcontroller.ProjectManagementController"
            <put name="body" value="/projectmanagement_list.htm"/>
    </definition>
    don’t use beans defined in the springcontext.

    So if you would like to use a frontcontroller (from spring bean definition) or something in that way, there is no real “smooth? solution, isn’t it?

    I tried to find a solution, have a look:

    Swdtool is the name of my web application. So it can handle all request ending with *.htm and *.tiles. Destination is to use tiles mapping with *.tiles and controller mapping with *.htm

    Web.xml:
    Code:
    <servlet-mapping>
            <servlet-name>FacesServlet</servlet-name>
            <url-pattern>*.jsf</url-pattern>
        </servlet-mapping>
        <servlet-mapping>
            <servlet-name>FacesServlet</servlet-name>
            <url-pattern>*.faces</url-pattern>
        </servlet-mapping>
               	
    	<servlet-mapping>
    		<servlet-name>swdtool</servlet-name>
    		<url-pattern>*.htm</url-pattern>
    	</servlet-mapping>
    	<servlet-mapping>
    		<servlet-name>swdtool</servlet-name>
    		<url-pattern>*.tiles</url-pattern>
    	</servlet-mapping>
    As you can see in the urlMapping all *.tiles requests are handled by the viewController and the *.html request maps to the specific frontcontroller.
    Swdtool-servlet.xml:
    Code:
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass">
    <value>org.springframework.web.servlet.view.tiles.TilesJstlView</value>
    </property>
    </bean>
    
    	<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles.TilesConfigurer">
    		<property name="factoryClass" value="org.apache.struts.tiles.xmlDefinition.I18nFactorySet"/>
    		<property name="definitions">
    			<list>
    				<value>/WEB-INF/tiles.xml</value>
    			</list>
    		</property>
    	</bean>
    
        <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="mappings">
                <props>               
                    <prop key="/projectmanagement_list.htm">ProjectManagementController</prop>
                    <prop key="/*.tiles">viewController</prop>
                </props>
            </property>
        </bean>
    
       <bean id="viewController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>

    Tilesdefiniton maps the first request to “projectmanagement_list.htm?. Then the Frontcontroller ProjectManagementController (defined in another applicationContext.xml) is called by the SimpleUrlHandlerMapping. The ProjectManagementController returns ModelAndView with param “ProjectManagementMain?. Now Tilesdefiniton maps to the real jsp / faces file.
    Tiles.xml:
    Code:
        <definition name="layout.example" path="/template/template.faces" >
            <put name="header" value="/common/header.faces" />
            <put name="menu" value="/common/navigation.faces" />
        </definition>
    
        <definition name="projectmanagement_list" extends="layout.example">
           <put name="body" value="/projectmanagement_list.htm"/>
        </definition>
        <definition name="ProjectManagementMain" extends="layout.example">
            <put name="body" value="/jsp/projectmanagement_list.faces"/>
        </definition>
    Starting request with:
    Index.jsp:
    Code:
    <c&#58;redirect url="/projectmanagement_list.tiles"/>
    This construct works except this stupid exception.
    This exception is also present when not using this “double mapping?, so even if I use a controllerClass definition in tiles.xml to prevent a second mapping execution.
    Code:
    2005-10-21 10&#58;46&#58;12,937 ERROR &#91;org.apache.catalina.core.ContainerBase.&#91;Catalina&#93;.&#91;localhost&#93;.&#91;/swdtool&#93;.&#91;FacesServlet&#93;&#93; - <Servlet.service&#40;&#41; for servlet FacesServlet threw exception>
    java.lang.IllegalStateException&#58; Cannot forward after response has been committed
    	at org.apache.catalina.core.ApplicationDispatcher.doForward&#40;ApplicationDispatcher.java&#58;313&#41;
    	at org.apache.catalina.core.ApplicationDispatcher.forward&#40;ApplicationDispatcher.java&#58;301&#41;
    	at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch&#40;ServletExternalContextImpl.java&#58;415&#41;
    	at 
    
    - - - - 
    
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run&#40;ThreadPool.java&#58;684&#41;
    	at java.lang.Thread.run&#40;Thread.java&#58;595&#41;
    2005-10-21 10&#58;46&#58;12,953 ERROR &#91;org.apache.struts.taglib.tiles.InsertTag&#93; - <ServletException in '/common/navigation.faces'&#58; Cannot forward after response has been committed>
    javax.servlet.ServletException&#58; Cannot forward after response has been committed
    	at javax.faces.webapp.FacesServlet.service&#40;FacesServlet.java&#58;109&#41;
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter&#40;ApplicationFilterChain.java&#58;252&#41;
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter&#40;ApplicationFilterChain.java&#58;173&#41;
    	
    
    - - - - 
    
    	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run&#40;ThreadPool.java&#58;684&#41;
    	at java.lang.Thread.run&#40;Thread.java&#58;595&#41;
    2005-10-21 10&#58;46&#58;12,984 ERROR &#91;org.apache.catalina.core.ContainerBase.&#91;Catalina&#93;.&#91;localhost&#93;.&#91;/swdtool&#93;.&#91;jsp&#93;&#93; - <Servlet.service&#40;&#41; for servlet jsp threw exception>
    javax.servlet.jsp.JspException&#58; ServletException in '/common/navigation.faces'&#58; Cannot forward after response has been committed
    	at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag&#40;InsertTag.java&#58;921&#41;
    	at org.apache.struts.taglib.tiles.InsertTag.doEndTag&#40;InsertTag.java&#58;460&#41;
    	at org.apache.jsp.template.template_jsp._jspx_meth_tiles_insert_0&#40;org.apache.jsp.template.template_jsp&#58;178&#41;
    	at org.apache.jsp.template.template_jsp._jspx_meth_f_subview_0&#40;org.apache.jsp.template.template_jsp&#58;156&#41;
    	
    - - - - 
    
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run&#40;ThreadPool.java&#58;684&#41;
    	at java.lang.Thread.run&#40;Thread.java&#58;595&#41;
    2005-10-21 10&#58;46&#58;13,156 ERROR &#91;org.apache.catalina.core.ContainerBase.&#91;Catalina&#93;.&#91;localhost&#93;.&#91;/swdtool&#93;.&#91;FacesServlet&#93;&#93; - <Servlet.service&#40;&#41; for servlet FacesServlet threw exception>
    javax.faces.FacesException&#58; ServletException in '/common/navigation.faces'&#58; Cannot forward after response has been committed
    	at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch&#40;ServletExternalContextImpl.java&#58;421&#41;
    	at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView&#40;JspViewHandlerImpl.java&#58;234&#41;
    	
    - - - - 
    
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run&#40;ThreadPool.java&#58;684&#41;
    	at java.lang.Thread.run&#40;Thread.java&#58;595&#41;
    Caused by&#58; javax.servlet.ServletException&#58; ServletException in '/common/navigation.faces'&#58; Cannot forward after response has been committed
    	at org.apache.jasper.runtime.PageContextImpl.doHandlePageException&#40;PageContextImpl.java&#58;848&#41;
    	at org.apache.jasper.runtime.PageContextImpl.handlePageException&#40;PageContextImpl.java&#58;781&#41;
    
    - - - -
    
    org.apache.catalina.core.ApplicationDispatcher.forward&#40;ApplicationDispatcher.java&#58;301&#41;
    	at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch&#40;ServletExternalContextImpl.java&#58;415&#41;
    	... 32 more
    2005-10-21 10&#58;46&#58;13,171 ERROR &#91;org.springframework.web.servlet.DispatcherServlet&#93; - <Could not complete request>
    javax.servlet.ServletException&#58; ServletException in '/common/navigation.faces'&#58; Cannot forward after response has been committed
    	at javax.faces.webapp.FacesServlet.service&#40;FacesServlet.java&#58;109&#41;
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter&#40;ApplicationFilterChain.java&#58;252&#41;
    	
    
    - - - - 
    
    	at java.lang.Thread.run&#40;Thread.java&#58;595&#41;
    2005-10-21 10&#58;46&#58;13,187 ERROR &#91;org.apache.catalina.core.ContainerBase.&#91;Catalina&#93;.&#91;localhost&#93;.&#91;/swdtool&#93;.&#91;swdtool&#93;&#93; - <Servlet.service&#40;&#41; for servlet swdtool threw exception>
    javax.faces.FacesException&#58; ServletException in '/common/navigation.faces'&#58; Cannot forward after response has been committed
    	at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch&#40;ServletExternalContextImpl.java&#58;421&#41;
    	at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView&#40;JspViewHandlerImpl.java&#58;234&#41;
    	
    - - - - 
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run&#40;ThreadPool.java&#58;684&#41;
    	at java.lang.Thread.run&#40;Thread.java&#58;595&#41;
    Caused by&#58; javax.servlet.ServletException&#58; ServletException in '/common/navigation.faces'&#58; Cannot forward after response has been committed
    	at org.apache.jasper.runtime.PageContextImpl.doHandlePageException&#40;PageContextImpl.java&#58;848&#41;
    	
    . . .

    I already deleted in the jsps all
    Code:
    	<%@ page session="true" %>
    And I used flush=?false?
    Code:
    	
          <tiles&#58;insert attribute="menu" flush="false" />

    Can anyone help me?


    Btw: This way using tiles is like spring recommend. Would it be a better solution to use tiles strictly the myfaces way ?

  • #2
    I'm struggling with just about the same problem, so I got no real answer for you.

    But this has been discussed in many threads here and I'm surprised this has not been addressed more elegantly.

    I'm trying right now to put some Tiles in my Freemarker templates. I stumble into the same problems as the thread starter. I may get it to work, but it does feel like a hack for a common requirement.

    I could use Tiles alltogether, but I do not like the framework and I'm not certain I can do all the things I want.

    This must be a common task and should have a generic solution:

    A Page has 1..n page elements, each realizing one use-case.

    Example page:
    • top: Dynamic menu
      main: List the top selling products
      left box1: List the top 5 titles in category X
      left box2: List online users
      right box: Login form
      right box2: List some articles from a RSS feed

    Each of these elements requires a model. For most of these use cases the model could be populated from the same controller, but they are not very related.

    The dynamic menu could be handled through a HandlerInterceptorAdapter, but what about the "Login form"? It needs a Command object and it's own Controller.

    ASP.NET has made an elegant solution for this, me thinks. Maybe someone could make JSP.NET?

    Comment

    Working...
    X