You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Pauli Savolainen <sa...@gmail.com> on 2008/02/28 14:08:06 UTC

Struts 2 Tiles 2 Runtime composition

Hi,

I am attempting to change an existing tiles definition during an execution
of a Struts action. Example tiles definition:

<definition name="layout" template="/layout.jsp">
  <put-attribute name="head" value="/head.jsp" />
  <put-attribute name="body" value="/login.jsp" />
</definition>

In the action I want to choose a correct body value based on some
application specific rules. For example if I call:  /user/1, the User
action's show method is executed and the body attribute's value would turn
into /user/show.jsp. This would prevent me from writing definitions for each
possible case.

Tile tutorial says I can get my hands on an attribute context (The class
TilesAttributeContext does not exist in my tiles plugin build). In the
action I do:

TilesAttributeContext attributeContext = container.startContext(request,
response);
attributeContext.setAttribute("body", "/user/show.jsp");
container.render("layout", request, response);
container.endContext(request, response);

I bet this is not the correct way to do it, because it seems that the tiles
definition overrides the value I insert here. Even if I do this in an
interceptor after the action result, the value is not changed.

I suppose there is no option in tiles to define definition with wildcards.
At least I did not find this option. I could point my action results
dynamically to a definition with wildcards.

<definition name="layout" template="/layout.jsp">
  <put-attribute name="head" value="/head.jsp" />
  <put-attribute name="body" value="/login.jsp" />
</definition>

<definition name="layout.*.*" extends="layout">
  <put-attribute name="body" value="/{1}/{2}.jsp" />
</definition>

So my question is how would I achieve what am I try to do? Am I on the right
tracks and just missing something, or is this even possible?

I am using 2.1.1-SNAPSHOT builds struts-core and struts tiles-plugin.

Thank you

Pauli

Re: Struts 2 Tiles 2 Runtime composition

Posted by Antonio Petrelli <an...@gmail.com>.
Please ask this question to Tiles Users mailing list:
http://tiles.apache.org/mail.html

Antonio

2008/2/28, Pauli Savolainen <sa...@gmail.com>:
> Hi,
>
>  I am attempting to change an existing tiles definition during an execution
>  of a Struts action. Example tiles definition:
>
>  <definition name="layout" template="/layout.jsp">
>   <put-attribute name="head" value="/head.jsp" />
>   <put-attribute name="body" value="/login.jsp" />
>  </definition>
>
>  In the action I want to choose a correct body value based on some
>  application specific rules. For example if I call:  /user/1, the User
>  action's show method is executed and the body attribute's value would turn
>  into /user/show.jsp. This would prevent me from writing definitions for each
>  possible case.
>
>  Tile tutorial says I can get my hands on an attribute context (The class
>  TilesAttributeContext does not exist in my tiles plugin build). In the
>  action I do:
>
>  TilesAttributeContext attributeContext = container.startContext(request,
>  response);
>  attributeContext.setAttribute("body", "/user/show.jsp");
>  container.render("layout", request, response);
>  container.endContext(request, response);
>
>  I bet this is not the correct way to do it, because it seems that the tiles
>  definition overrides the value I insert here. Even if I do this in an
>  interceptor after the action result, the value is not changed.
>
>  I suppose there is no option in tiles to define definition with wildcards.
>  At least I did not find this option. I could point my action results
>  dynamically to a definition with wildcards.
>
>  <definition name="layout" template="/layout.jsp">
>   <put-attribute name="head" value="/head.jsp" />
>   <put-attribute name="body" value="/login.jsp" />
>  </definition>
>
>  <definition name="layout.*.*" extends="layout">
>   <put-attribute name="body" value="/{1}/{2}.jsp" />
>  </definition>
>
>  So my question is how would I achieve what am I try to do? Am I on the right
>  tracks and just missing something, or is this even possible?
>
>  I am using 2.1.1-SNAPSHOT builds struts-core and struts tiles-plugin.
>
>  Thank you
>
>
>  Pauli
>

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