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/05/01 16:49:28 UTC

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

I am still hoping someone with more familiarity with JSP and servlets can
offer up the answer
to this problem.  I doubt switching layouts dynamically is common, however,
the processing
associated with ServletContext's and RequestDispatcher's and where they
look for files
to include is.  To rephrase the problem, the "tiles:include" within the
layout.jsp should look relative
to its location.  You might also notice that in the tile definition, the
header and footer offer
relative files, but the body is an absolute path.  It is looking relative
to its location in Struts v1.0
but it is not in Struts v1.1rc1.

Any help you can offer would be greatly appreciated.

Bob Byron



                                                                                                                               
                    Bob.Byron@tran                                                                                             
                    splace.com           To:     struts-user@jakarta.apache.org                                                
                                         cc:                                                                                   
                    04/30/2003           Subject:     Switching layouts in tiles - struts 1.0 vs 1.1 (I have a problem)        
                    10:42 AM                                                                                                   
                    Please respond                                                                                             
                    to "Struts                                                                                                 
                    Users Mailing                                                                                              
                    List"                                                                                                      
                                                                                                                               
                                                                                                                               




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