+1

David Friedman wrote:

Janne,

You could set everything dynamically in the tile using something like this
(don't quote me if you like it, just look it up!):

public class TestAction extends TilesAction {
        public ActionForward execute(ComponentContext context,
                        ActionMapping mapping, ActionForm form, HttpServletRequest 
request,
                        HttpServletResponse response) throws Exception {

                if (request.isUserInRole("admin")) {
                        context.putAttribute("menu", new String("menu-admin.jsp"));
                } else {
                        context.putAttribute("menu", new String("menu-user.jsp"));
                }
                return super.execute(mapping, form, request, response);
        }
}

Then, you don't need the unstandard:bind or EL tags, just the tiles:insert
tags.

For more information, I recommend you read the Tiles Advanced Features by
Cedric Dumoulin.  Link (from the bottom of the "Developer Guide" subsection
"Tiles" page http://struts.apache.org/userGuide/dev_tiles.html) is:
http://www.lifl.fr/~dumoulin/tiles/tilesAdvancedFeatures.pdf

Regards,
David

-----Original Message-----
From: Janne Mattila [mailto:[EMAIL PROTECTED]
Sent: Friday, August 27, 2004 3:09 AM
To: [EMAIL PROTECTED]
Subject: Tiles - proper way for choosing a tile dynamically


I use Tiles to create pages that have their tiles selected dynamically based on some information that is created in an action. One simple example could be a menu tile, which is selected based on an attribute that is stored in session. I created simple definitions like:

        <definition name=".layout.basic-cd"
path="/pages/cd/layout/basicTemplate.jsp">
                <put name="topleft" value="/pages/cd/content/common/topleft.jsp" />
                <put name="header" 
value="/pages/cd/content/common/logged-in-header.jsp"
/>
                <put name="menu" value="/pages/cd/content/common/menu.jsp" />
                <put name="bottomleft" value="/pages/cd/content/common/bottomleft.jsp" 
/>
                <put name="footer" value="/pages/cd/content/common/footer.jsp" />
        </definition>

   <definition name=".page.main" extends=".layout.basic-cd">
                <put name="content" value="/pages/cd/content/main.jsp"/>
   </definition>

  ...

then, in menu.jsp page I include either "admin" menu or "user" menu based on
the session parameter:

<unstandard:bind var="AdminRole" type="cd.business.Role" field="ADMIN"/>
<unstandard:bind var="UserRole" type="cd.business.Role" field="USER"/>
<c:choose>
<c:when test="${sessionScope.role == AdminRole}">
 <tiles:insert page="menu-admin.jsp" />
</c:when>
<c:when test="${sessionScope.role == UserRole}">
 <tiles:insert page="menu-user.jsp" />
</c:when>
</c:choose>

Now the question: is this the "proper" way to do this, or is there a more
elegant method?



PS. if those <unstandard:bind> tags confuse, they use jakarta unstandard
taglib to enable JSTL to compare the object in session to typesafe
enumeration values. In scriptlets this would be written simply as

<% if (cd.business.Role.ADMIN.equals(session.getAttribute("role")) { %>
 <tiles:insert page="menu-admin.jsp" />
...

_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]









--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to