You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ken Riley <kr...@allconnect.com> on 2002/10/22 23:18:57 UTC

[TILES] Problem using struts actions in tile's template

I'm probably being dense here (not an uncommon occurance) but I seem to be unable to 
create a tile layout that uses multiple actions. I have a sample below that I'm using to 
test. When I run this, I don't get any output for the header.do action call. Ultimately I would
like to have a layout that calls 4 or 5 actions but I'd like to get my test app working first :).

--------struts-config.xml-------
<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
          "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
  <form-beans></form-beans>

  <action-mappings>
    <action    path="/header"
               type="com.mycompany.test.HeaderAction">
		<forward name="success" path="/jsp/header.jsp"/>              
    </action>
  
    <action    path="/content"
               type="com.mycompany.test.HeaderAction">
		<forward name="success" path="/jsp/content.jsp"/>              
    </action>
  </action-mappings>
</struts-config>
-------END struts-config.xml-----

------temptest.jsp---------------
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<tiles:insert template="/template.jsp">
    <tiles:put name="title" content="Service Address" direct="true" />
    <tiles:put name="header" content="/header.do" />
    <tiles:put name="content" content="/content.do"/>
</tiles:insert>
------END temptest.jsp-----------

------template.jsp---------------
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>

<html:html>
<head><title><tiles:get name="title"/></title>
</head>
<body>
<table align="left" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><tiles:get name="header" /></td></tr>
<tr><td></td></tr>
<tr><td>
   <table border="0" cellspacing="0" cellpadding="0" width="100%">
   <tr>
   <td></td>
   <td><tiles:get name="content"/></td>
   </tr></table></td>

</tr>
<tr><td></td></tr>
</table>
</body>
</html:html>
------END template.jsp-----------

------header.jsp-----------------
<h3>THIS IS THE HEADER!!!!</h3>
------END header.jsp-------------

------content.jsp----------------
<B>THIS IS THE CONTENT!!</B>
------END content.jsp------------

Note:HeaderAction and ContentAction are identical except for their name. just used for testing
------ContentAction.java---------
package com.mycompany.test;

import org.apache.struts.action.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;

public class ContentAction extends Action {

    public ActionForward perform(ActionMapping mapping,
                 ActionForm form,
                 HttpServletRequest request,
                 HttpServletResponse response)
    throws IOException, ServletException {

        return mapping.findForward("success");  
    }

}
-----END ContentAction.java------

The output I get (Struts 1.1b2/Tomcat 4.1.12)
[Exception in:/header.do] Cannot forward after response has been committed   
[Exception in:/content.do] Cannot forward after response has been committed  

Thanks for any help/suggestions! 

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: [TILES] Problem using struts actions in tile's template

Posted by James Mitchell <jm...@telocity.com>.
Ken, (long time no type)

It's hard (for me at least) to determine the problem from those spots of
code, but I have a working example that (I think) will demonstrate just what
you are trying to do.

The site it listed below (in my sig block) and the source is available here:
http://www.open-tools.org/struts-atlanta/downloads



James Mitchell
Software Engineer/Struts Evangelist
http://www.open-tools.org

"Only two things are infinite, the universe and human stupidity, and I'm not
sure about the former."
- Albert Einstein (1879-1955)


> -----Original Message-----
> From: Ken Riley [mailto:kriley@allconnect.com]
> Sent: Tuesday, October 22, 2002 5:19 PM
> To: Struts Users Mailing List
> Subject: [TILES] Problem using struts actions in tile's template
>
>
> I'm probably being dense here (not an uncommon occurance) but I
> seem to be unable to
> create a tile layout that uses multiple actions. I have a sample
> below that I'm using to
> test. When I run this, I don't get any output for the header.do
> action call. Ultimately I would
> like to have a layout that calls 4 or 5 actions but I'd like to
> get my test app working first :).
>
> --------struts-config.xml-------
> <?xml version="1.0" encoding="ISO-8859-1" ?>
>
> <!DOCTYPE struts-config PUBLIC
>           "-//Apache Software Foundation//DTD Struts
> Configuration 1.0//EN"
>           "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
> <struts-config>
>   <form-beans></form-beans>
>
>   <action-mappings>
>     <action    path="/header"
>                type="com.mycompany.test.HeaderAction">
> 		<forward name="success" path="/jsp/header.jsp"/>
>
>     </action>
>
>     <action    path="/content"
>                type="com.mycompany.test.HeaderAction">
> 		<forward name="success" path="/jsp/content.jsp"/>
>
>     </action>
>   </action-mappings>
> </struts-config>
> -------END struts-config.xml-----
>
> ------temptest.jsp---------------
> <%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
> <tiles:insert template="/template.jsp">
>     <tiles:put name="title" content="Service Address" direct="true" />
>     <tiles:put name="header" content="/header.do" />
>     <tiles:put name="content" content="/content.do"/>
> </tiles:insert>
> ------END temptest.jsp-----------
>
> ------template.jsp---------------
> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
> <%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
>
> <html:html>
> <head><title><tiles:get name="title"/></title>
> </head>
> <body>
> <table align="left" width="100%" border="0" cellspacing="0"
> cellpadding="0">
> <tr><td><tiles:get name="header" /></td></tr>
> <tr><td></td></tr>
> <tr><td>
>    <table border="0" cellspacing="0" cellpadding="0" width="100%">
>    <tr>
>    <td></td>
>    <td><tiles:get name="content"/></td>
>    </tr></table></td>
>
> </tr>
> <tr><td></td></tr>
> </table>
> </body>
> </html:html>
> ------END template.jsp-----------
>
> ------header.jsp-----------------
> <h3>THIS IS THE HEADER!!!!</h3>
> ------END header.jsp-------------
>
> ------content.jsp----------------
> <B>THIS IS THE CONTENT!!</B>
> ------END content.jsp------------
>
> Note:HeaderAction and ContentAction are identical except for
> their name. just used for testing
> ------ContentAction.java---------
> package com.mycompany.test;
>
> import org.apache.struts.action.*;
> import javax.servlet.http.*;
> import javax.servlet.*;
> import java.io.*;
>
> public class ContentAction extends Action {
>
>     public ActionForward perform(ActionMapping mapping,
>                  ActionForm form,
>                  HttpServletRequest request,
>                  HttpServletResponse response)
>     throws IOException, ServletException {
>
>         return mapping.findForward("success");
>     }
>
> }
> -----END ContentAction.java------
>
> The output I get (Struts 1.1b2/Tomcat 4.1.12)
> [Exception in:/header.do] Cannot forward after response has been
> committed
> [Exception in:/content.do] Cannot forward after response has been
> committed
>
> Thanks for any help/suggestions!
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>