You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by stanlick <st...@gmail.com> on 2008/04/17 16:18:51 UTC
Tiles2 runtime definition
I need to set a runtime tiles definition attribute using a value from the
valuestack. From my research, the tiles-plugin result does not allow
attributes to be configured.
<action name="wizard_*" class="acme.action.wizard.Wizard" method="{1}">
<result>${nextPage}</result>
</action>
<definition name="wizardPage" extends="baseLayout">
<put-attribute name="body" value="???{nextPage}???" />
</definition>
Can someone help me navigate this configuration? I'd rather not duplicate
the tiles definitions when the only variation is the jsp page in the
sequence.
Thanks,
Scott
--
View this message in context: http://www.nabble.com/Tiles2-runtime-definition-tp16744033p16744033.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Tiles2 runtime definition
Posted by Antonio Petrelli <an...@gmail.com>.
2008/4/17, stanlick@gmail.com <st...@gmail.com>:
>
> I think the tiles definition attributes should be exposed through the
> tiles-plugin XML file.
Can you elaborate on this? I wish to know what's your point.
Thanks
Antonio
Re: Tiles2 runtime definition
Posted by st...@gmail.com.
I think the tiles definition attributes should be exposed through the
tiles-plugin XML file. My Wizard action is setting the nextPage so this
would eliminate the need to write a ViewPreparer to set the jsp in the tiles
definition. I am now meddling around in the Preparer trying to construct
the URL that contains the page. For this Preparer to be flexible, I really
don't want to presuppose anything.
ValueStack stack = (ValueStack) tilesContext.getRequestScope().get(
ServletActionContext.STRUTS_VALUESTACK_KEY);
String nextPage = stack.findString("nextPage");
HttpServletRequest request = (HttpServletRequest)
tilesContext.getRequest();
String fullUrl = request.getRequestURL().toString();
// find last slash and strip everything following
// int index = fullUrl.lastIndexOf("/");
// fullUrl = fullUrl.substring(0, index);
// MORE MESSY CODE HERE <-----------
// GROSS!!!
nextPage = "/tiles/wizard/"+nextPage+".jsp";
attributeContext.putAttribute(
"body",
new Attribute(nextPage));
On Thu, Apr 17, 2008 at 2:39 PM, Antonio Petrelli <
antonio.petrelli@gmail.com> wrote:
> 2008/4/17, stanlick@gmail.com <st...@gmail.com>:
> > Right on Antonio! Can you tell me how to fish the web context root from
> the
> > Preparer? I need to construct the page location from this and the
> nextPage
> > itself. Is there a list of key names someplace? Finding this bit of
> data
> > or that on the stack is typically where productivity takes a nosedive.
> I
> > used this key to get the stack:
> >
> > stack = (ValueStack)
> >
> tilesContext.getRequestScope().get(ServletActionContext.STRUTS_VALUESTACK_KEY);
>
> Unfortunately, Tiles plugin is not "so integrated" to Struts 2, so you
> have to access the value stack in another way.
> The TilesRequestContext.getRequest returns the request object, simply
> cast it to HttpServletRequest (in most cases).
> And the use the ServletActionContext.getValueStackMethod:
>
> http://struts.apache.org/2.0.11.1/struts2-core/apidocs/org/apache/struts2/ServletActionContext.html#getValueStack(javax.servlet.http.HttpServletRequest)<http://struts.apache.org/2.0.11.1/struts2-core/apidocs/org/apache/struts2/ServletActionContext.html#getValueStack%28javax.servlet.http.HttpServletRequest%29>
>
>
> HTH
> Antonio
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
Scott
stanlick@gmail.com
Re: Tiles2 runtime definition
Posted by Antonio Petrelli <an...@gmail.com>.
2008/4/17, stanlick@gmail.com <st...@gmail.com>:
> Right on Antonio! Can you tell me how to fish the web context root from the
> Preparer? I need to construct the page location from this and the nextPage
> itself. Is there a list of key names someplace? Finding this bit of data
> or that on the stack is typically where productivity takes a nosedive. I
> used this key to get the stack:
>
> stack = (ValueStack)
> tilesContext.getRequestScope().get(ServletActionContext.STRUTS_VALUESTACK_KEY);
Unfortunately, Tiles plugin is not "so integrated" to Struts 2, so you
have to access the value stack in another way.
The TilesRequestContext.getRequest returns the request object, simply
cast it to HttpServletRequest (in most cases).
And the use the ServletActionContext.getValueStackMethod:
http://struts.apache.org/2.0.11.1/struts2-core/apidocs/org/apache/struts2/ServletActionContext.html#getValueStack(javax.servlet.http.HttpServletRequest)
HTH
Antonio
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Tiles2 runtime definition
Posted by st...@gmail.com.
Right on Antonio! Can you tell me how to fish the web context root from the
Preparer? I need to construct the page location from this and the nextPage
itself. Is there a list of key names someplace? Finding this bit of data
or that on the stack is typically where productivity takes a nosedive. I
used this key to get the stack:
stack = (ValueStack)
tilesContext.getRequestScope().get(ServletActionContext.STRUTS_VALUESTACK_KEY);
Thanks brother
On Thu, Apr 17, 2008 at 9:48 AM, Antonio Petrelli <
antonio.petrelli@gmail.com> wrote:
> 2008/4/17, stanlick <st...@gmail.com>:
> >
> > <definition name="wizardPage" extends="baseLayout">
> > <put-attribute name="body" value="???{nextPage}???" />
> > </definition>
>
>
>
> Use a ViewPreparer:
> http://tiles.apache.org/tutorial/advanced/preparer.html
>
> Antonio
>
--
Scott
stanlick@gmail.com
Re: Tiles2 runtime definition
Posted by Antonio Petrelli <an...@gmail.com>.
2008/4/17, stanlick <st...@gmail.com>:
>
> <definition name="wizardPage" extends="baseLayout">
> <put-attribute name="body" value="???{nextPage}???" />
> </definition>
Use a ViewPreparer:
http://tiles.apache.org/tutorial/advanced/preparer.html
Antonio