You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bo...@transplace.com on 2003/04/30 17:42:25 UTC

Switching layouts in tiles - struts 1.0 vs 1.1 (I have a problem)

I am exploiting an interesting feature in Tiles.  The Tiles documentation
shows how you can dynamically change the look and feel.  One user can
login and have the site look one way, while the site appears different
to another use.  The problem is that v1.0 and v1.1 of Struts seem to
act differently when I switch layouts.  This is a very long description
of the problem, but I wanted to be complete in the description of what
is wrong.

Refer to section 7.4.3 (dynamic look and feel) in this document:
  http://www.lifl.fr/~dumoulin/tiles/tilesAdvancedFeatures.pdf

I have found that the action seems to work differently between version
Struts 1.0 vs. Struts 1.1 rc1.

Here is the code for the SwitchLayoutAction (derived from the above
document).
-----------------------------------------------------
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.tiles.actions.*;

public class SimpleSwitchLayoutAction extends TilesAction {
  public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {

    String layoutDir = "/layouts";
    String skin = getUserSkin(); //This returns the user's skin
    String layout = "layout.jsp";
    String layoutPath = layoutDir+"/"+skin+"/"+layout;
    RequestDispatcher rd = getServlet().getServletContext
().getRequestDispatcher( layoutPath );
    if(rd==null)
      throw new ServletException( "SwitchLayout error : Can't find layout
'" + layoutPath + "'." );
    rd.include(request, response);

    return null;
  }

//skin is hardcoded for now.
  public getUserSkin() {
    return "aqua";
  }
}
-----------------------------------------------------

Here is the layout.jsp file:
-----------------------------------------------------
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<HTML>
  <body>
    <table border="0" width="100%" cellspacing="0">
      <tr><td><tiles:insert attribute="header" /></td></tr>
      <tr><td><tiles:insert attribute='body' /></td></tr>
      <tr><td><tiles:insert attribute="footer" /></td></tr>
    </table>
  </body>
</HTML>
-----------------------------------------------------

The tile definition looks like this:
-----------------------------------------------------
  <definition name="example.layout.common" path="/switchLayout.do">
    <put name="header" value="header.jsp"/>
    <put name="body" value="/jsps/body.jsp"/>
    <put name="footer" value="footer.jsp"/>
  </definition>
-----------------------------------------------------

Problem:
In Struts v1.0 this method worked pretty well.  The skins switched
and displayed propertly.

In Struts v1.1 the header and footer are no longer found.  Struts
(or tiles) is looking for the files in a different place.  Basically,
it appears that v1.0 uses the directory where the layout.jsp file
is found as a base.  That is, the directory found in
    String layoutPath = layoutDir+"/"+skin+"/"+layout;
is used as a base.  In v1.1 the path is being ignored totally and
the file is being looked for without the prepended
layoutDir+"/"+skin+"/" and therefore, the file is not found.  So,
the big question is, how do I get tiles to find the files?  The
"insert" listed in the layout.jsp above needs to find files
relative to its location, and it is not.

Any help would be appreciated,
Bob Byron




---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Switching layouts in tiles - struts 1.0 vs 1.1 (I have a problem)

Posted by Cedric Dumoulin <ce...@apache.org>.
 
  Try to use the later nightly builds of Struts/Tiles. The Struts1.1rc1 
use a different implementation for the <insert ...>, which is not 
compatible with relative paths. The problem has been corrected in the 
nightly builds.

  Cedric

Bob.Byron@transplace.com wrote:

>I am exploiting an interesting feature in Tiles.  The Tiles documentation
>shows how you can dynamically change the look and feel.  One user can
>login and have the site look one way, while the site appears different
>to another use.  The problem is that v1.0 and v1.1 of Struts seem to
>act differently when I switch layouts.  This is a very long description
>of the problem, but I wanted to be complete in the description of what
>is wrong.
>
>Refer to section 7.4.3 (dynamic look and feel) in this document:
>  http://www.lifl.fr/~dumoulin/tiles/tilesAdvancedFeatures.pdf
>
>I have found that the action seems to work differently between version
>Struts 1.0 vs. Struts 1.1 rc1.
>
>Here is the code for the SwitchLayoutAction (derived from the above
>document).
>-----------------------------------------------------
>import javax.servlet.*;
>import javax.servlet.http.*;
>import org.apache.struts.action.*;
>import org.apache.struts.tiles.actions.*;
>
>public class SimpleSwitchLayoutAction extends TilesAction {
>  public ActionForward execute(ActionMapping mapping, ActionForm form,
>    HttpServletRequest request, HttpServletResponse response)
>    throws IOException, ServletException {
>
>    String layoutDir = "/layouts";
>    String skin = getUserSkin(); //This returns the user's skin
>    String layout = "layout.jsp";
>    String layoutPath = layoutDir+"/"+skin+"/"+layout;
>    RequestDispatcher rd = getServlet().getServletContext
>().getRequestDispatcher( layoutPath );
>    if(rd==null)
>      throw new ServletException( "SwitchLayout error : Can't find layout
>'" + layoutPath + "'." );
>    rd.include(request, response);
>
>    return null;
>  }
>
>//skin is hardcoded for now.
>  public getUserSkin() {
>    return "aqua";
>  }
>}
>-----------------------------------------------------
>
>Here is the layout.jsp file:
>-----------------------------------------------------
><%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
><HTML>
>  <body>
>    <table border="0" width="100%" cellspacing="0">
>      <tr><td><tiles:insert attribute="header" /></td></tr>
>      <tr><td><tiles:insert attribute='body' /></td></tr>
>      <tr><td><tiles:insert attribute="footer" /></td></tr>
>    </table>
>  </body>
></HTML>
>-----------------------------------------------------
>
>The tile definition looks like this:
>-----------------------------------------------------
>  <definition name="example.layout.common" path="/switchLayout.do">
>    <put name="header" value="header.jsp"/>
>    <put name="body" value="/jsps/body.jsp"/>
>    <put name="footer" value="footer.jsp"/>
>  </definition>
>-----------------------------------------------------
>
>Problem:
>In Struts v1.0 this method worked pretty well.  The skins switched
>and displayed propertly.
>
>In Struts v1.1 the header and footer are no longer found.  Struts
>(or tiles) is looking for the files in a different place.  Basically,
>it appears that v1.0 uses the directory where the layout.jsp file
>is found as a base.  That is, the directory found in
>    String layoutPath = layoutDir+"/"+skin+"/"+layout;
>is used as a base.  In v1.1 the path is being ignored totally and
>the file is being looked for without the prepended
>layoutDir+"/"+skin+"/" and therefore, the file is not found.  So,
>the big question is, how do I get tiles to find the files?  The
>"insert" listed in the layout.jsp above needs to find files
>relative to its location, and it is not.
>
>Any help would be appreciated,
>Bob Byron
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org