You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by Lars Dam <la...@gmail.com> on 2008/04/28 14:30:20 UTC

Proper way to use a definition attribute as argument or parameter for an action?

I am trying to make some kind of jsp 'component' page that can be reused
multiple times with different datasets on a single jsp page. When defining
the templates i use i can give some arguments that i can access on the
template page, but how can i use these arguments on the action?

If i have a jsp page that contains two templates like:
:
<tiles:insertTemplate template="/someminorjsppage.jsp">
    <tiles:putAttribute name="title" value="some.title.i18n.key"/>
    <tiles:putAttribute name="argument" value="someargument"/>
</tiles:insertTemplate>
:
<tiles:insertTemplate template="/someminorjsppage.jsp">
    <tiles:putAttribute name="title" value="some.title.i18n.key"/>
    <tiles:putAttribute name="argument" value="anotherargument"/>
</tiles:insertTemplate>
:

What would be the proper way to send the value of "argument" to the action,
so the action could use this to find data for the jsp page?

Would it be possible to have some kind of callback to the action that gets
the 'argument' attribute as parameter?

Or am i on some completely wrong track of how to do this?

kr. Lars Dam

Re: Proper way to use a definition attribute as argument or parameter for an action?

Posted by Antonio Petrelli <an...@gmail.com>.
2008/5/2 Lars Dam <la...@gmail.com>:
>  using ${argument} prints out the toString() of my object, as ${argument.name}
>  prints out the name; now i just need to the enxt step: How do i put this
>  object into the value stack so i can use it properly?

Well... Sorry for not being a Struts 2 expert, but in this case I
think you have to ask the Struts Users mailing list:
http://struts.apache.org/mail.html

Antonio

Re: Proper way to use a definition attribute as argument or parameter for an action?

Posted by Lars Dam <la...@gmail.com>.
Hi

Got it working so far:

using ${argument} prints out the toString() of my object, as ${argument.name}
prints out the name; now i just need to the enxt step: How do i put this
object into the value stack so i can use it properly?

kr. Lars Dam

On Wed, Apr 30, 2008 at 5:22 PM, Antonio Petrelli <
antonio.petrelli@gmail.com> wrote:

> 2008/4/30 Lars Dam <la...@gmail.com>:
> > outputting ${argument} shows content of toString() - using ${
> argument.name}
> >  gives me following error:
> >  "According to TLD or attribute directive in tag file, attribute value
> does
> >  not accept any expressions"
>
> Probably you are using <s:out>
> Don't use any tag, simply write ${argument.name} inside your JSP code
> outside of any JSP tag.
>
> Antonio
>

Re: Proper way to use a definition attribute as argument or parameter for an action?

Posted by Antonio Petrelli <an...@gmail.com>.
2008/4/30 Lars Dam <la...@gmail.com>:
> outputting ${argument} shows content of toString() - using ${argument.name}
>  gives me following error:
>  "According to TLD or attribute directive in tag file, attribute value does
>  not accept any expressions"

Probably you are using <s:out>
Don't use any tag, simply write ${argument.name} inside your JSP code
outside of any JSP tag.

Antonio

Re: Proper way to use a definition attribute as argument or parameter for an action?

Posted by Antonio Petrelli <an...@gmail.com>.
2008/4/30 Lars Dam <la...@gmail.com>:
>     <tiles:putAttribute name="argument">
>         <s:property value="map['key']"/>
>     </tiles:putAttribute>

This code is wrong, the tags are evaluated *before* they are put as
attribute. The path you followed before was mostly right, but I doubt
that your use inside <s:*> tags is right.

Antonio

Re: Proper way to use a definition attribute as argument or parameter for an action?

Posted by Lars Dam <la...@gmail.com>.
A small test revealed something interesting:

Removing all output from the jsp page, and printing to the console in the
toString() method of my object shows that the toString() method is called
when the property is inserted in the definition:
    <tiles:putAttribute name="argument">
        <s:property value="map['key']"/>
    </tiles:putAttribute>
So it seems to me that the properties that are placed on the attribute for
the someminorjsppage.jsp are strings, which means i will not get the object
to work on.

It means that i would have to send the key to my someminorjsppage.jsp page,
and use this key to dig into the map of the action.

Can anybody verify for me that this would be true?


kr.Lars Dam

On Wed, Apr 30, 2008 at 4:40 PM, Lars Dam <la...@gmail.com> wrote:

> outputting ${argument} shows content of toString() - using ${argument.name}
> gives me following error:
> "According to TLD or attribute directive in tag file, attribute value does
> not accept any expressions"
>
> To summarize:
> My tiles definition is:
>
>  <tiles:insertTemplate template="/someminorjsppage.jsp">
>     <tiles:putAttribute name="argument">
>         <s:property value="map['key']"/>
>     </tiles:putAttribute>
> </tiles:insertTemplate>
> My action has an attribute 'map' with objects mapped by keys, and i get
> the proper instance from the 'key'.
>
> The someminorjsppage.jsp is just:
>
> <%@ taglib prefix="s" uri="/struts-tags" %>
> <%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
> <%@ page contentType="text/html;charset=UTF-8" language="java" %>
> <tiles:importAttribute name="argument"/>
> <tiles:useAttribute name="argument"/>
> <%-- different suggestions below, tried one at the time --%>
> <tiles:getAsString name="component"/> <%-- gives output of toString() --%>
> <s:property value="argument.name" /> <%-- gives nothing, what i would like
> to get --%>
> <s:property value="argument" /> <%-- gives nothing  --%>
> ${argument} <%-- gives output of toString() --%>
> ${argument.name} <%-- gives the "According to..." error --%>
> It seems to me that i get the proper object from my map in my action,
> since it gives me proper toString() information (shows proper classname of
> instance i got from the map).
>
> But i have no idea of how i would use this instance properly in the jsp
> page - any pointers are welcome.
>
> kr. Lars Dam
>
>
>

Re: Proper way to use a definition attribute as argument or parameter for an action?

Posted by Lars Dam <la...@gmail.com>.
outputting ${argument} shows content of toString() - using ${argument.name}
gives me following error:
"According to TLD or attribute directive in tag file, attribute value does
not accept any expressions"

To summarize:
My tiles definition is:

<tiles:insertTemplate template="/someminorjsppage.jsp">
    <tiles:putAttribute name="argument">
        <s:property value="map['key']"/>
    </tiles:putAttribute>
</tiles:insertTemplate>
My action has an attribute 'map' with objects mapped by keys, and i get the
proper instance from the 'key'.

The someminorjsppage.jsp is just:

<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<tiles:importAttribute name="argument"/>
<tiles:useAttribute name="argument"/>
<%-- different suggestions below, tried one at the time --%>
<tiles:getAsString name="component"/> <%-- gives output of toString() --%>
<s:property value="argument.name" /> <%-- gives nothing, what i would like
to get --%>
<s:property value="argument" /> <%-- gives nothing  --%>
${argument} <%-- gives output of toString() --%>
${argument.name} <%-- gives the "According to..." error --%>
It seems to me that i get the proper object from my map in my action, since
it gives me proper toString() information (shows proper classname of
instance i got from the map).

But i have no idea of how i would use this instance properly in the jsp
page - any pointers are welcome.

kr. Lars Dam

On Wed, Apr 30, 2008 at 3:54 PM, Antonio Petrelli <
antonio.petrelli@gmail.com> wrote:

> 2008/4/30 Lars Dam <la...@gmail.com>:
> > I used the tiles:importAttribute, like:
> >
> >  <tiles:getAsString name="argument"/>
> >  but i dont get anything when i try to access this, using s: tags,e.g:
> >
> >  <s:property value="argument.name"/>
>
> IMO it is because it is not put inside the Struts value stack, but in
> the page scope.
> To be sure, try simple to output it:
> ${argument.name}
>
> Antonio
>

Re: Proper way to use a definition attribute as argument or parameter for an action?

Posted by Antonio Petrelli <an...@gmail.com>.
2008/4/30 Lars Dam <la...@gmail.com>:
> I used the tiles:importAttribute, like:
>
>  <tiles:getAsString name="argument"/>
>  but i dont get anything when i try to access this, using s: tags,e.g:
>
>  <s:property value="argument.name"/>

IMO it is because it is not put inside the Struts value stack, but in
the page scope.
To be sure, try simple to output it:
${argument.name}

Antonio

Re: Proper way to use a definition attribute as argument or parameter for an action?

Posted by Lars Dam <la...@gmail.com>.
I used the tiles:importAttribute, like:

<tiles:getAsString name="argument"/>
but i dont get anything when i try to access this, using s: tags,e.g:

<s:property value="argument.name"/>
It's probably something quite simple, but i dont see it :/

How would i go about displaying the name attribute of my argument attribute?

kr. ld


On Wed, Apr 30, 2008 at 2:52 PM, Antonio Petrelli <
antonio.petrelli@gmail.com> wrote:

> 2008/4/28 Lars Dam <la...@gmail.com>:
> >  <tiles:insertTemplate template="/someminorjsppage.jsp">
> >     <tiles:putAttribute name="title" value="some.title.i18n.key"/>
> >     <tiles:putAttribute name="argument" value="someargument"/>
> >  </tiles:insertTemplate>
> >  :
> >  Would it be possible to have some kind of callback to the action that
> gets
> >  the 'argument' attribute as parameter?
>
> Use <tiles:importAttribute>:
>
> http://tiles.apache.org/2.0/framework/tiles-jsp/tlddoc/tiles/importAttribute.html
>
> Antonio
>

Re: Proper way to use a definition attribute as argument or parameter for an action?

Posted by Antonio Petrelli <an...@gmail.com>.
2008/4/28 Lars Dam <la...@gmail.com>:
>  <tiles:insertTemplate template="/someminorjsppage.jsp">
>     <tiles:putAttribute name="title" value="some.title.i18n.key"/>
>     <tiles:putAttribute name="argument" value="someargument"/>
>  </tiles:insertTemplate>
>  :
>  Would it be possible to have some kind of callback to the action that gets
>  the 'argument' attribute as parameter?

Use <tiles:importAttribute>:
http://tiles.apache.org/2.0/framework/tiles-jsp/tlddoc/tiles/importAttribute.html

Antonio

Re: Proper way to use a definition attribute as argument or parameter for an action?

Posted by Lars Dam <la...@gmail.com>.
This works sort of. I get a value i can access using the <%= and
tiles:tiles:getAsString - but the <%=  gives me a string representation
where i would like to get the original object (which is retrieved from the
action).

It is also unclear for me how i would use this object on the jsp page?

I would be very happy if somebody could give me an example of how to
access/use the object that was placed in the 'argument' attribute (see
example) using struts2 tags in the someminorjsppage.jsp.

kr. Lars Dam

On Mon, Apr 28, 2008 at 9:07 PM, Chris Pratt <th...@gmail.com>
wrote:

> You can set the value of argument either using EL in the value=""
> attribute, or using JSP in the body of the putAttribute tag.
>
> Example:
>
>  <tiles:insertTemplate template="/someminorjsppage.jsp">
>     <tiles:putAttribute name="title" value="some.title.i18n.key"/>
>     <tiles:putAttribute name="argument" value="${myArgument}"/>
>  </tiles:insertTemplate>
>
>  <tiles:insertTemplate template="/someminorjsppage.jsp">
>     <tiles:putAttribute name="title" value="some.title.i18n.key"/>
>     <tiles:putAttribute name="argument"><s:property
> value="%{ognlValue}"/></tiles:putAttribute>
>  </tiles:insertTemplate>
>
> (*Chris*)
>
> On Mon, Apr 28, 2008 at 5:30 AM, Lars Dam <la...@gmail.com> wrote:
> > I am trying to make some kind of jsp 'component' page that can be reused
> >  multiple times with different datasets on a single jsp page. When
> defining
> >  the templates i use i can give some arguments that i can access on the
> >  template page, but how can i use these arguments on the action?
> >
> >  If i have a jsp page that contains two templates like:
> >  :
> >  <tiles:insertTemplate template="/someminorjsppage.jsp">
> >     <tiles:putAttribute name="title" value="some.title.i18n.key"/>
> >     <tiles:putAttribute name="argument" value="someargument"/>
> >  </tiles:insertTemplate>
> >  :
> >  <tiles:insertTemplate template="/someminorjsppage.jsp">
> >     <tiles:putAttribute name="title" value="some.title.i18n.key"/>
> >     <tiles:putAttribute name="argument" value="anotherargument"/>
> >  </tiles:insertTemplate>
> >  :
> >
> >  What would be the proper way to send the value of "argument" to the
> action,
> >  so the action could use this to find data for the jsp page?
> >
> >  Would it be possible to have some kind of callback to the action that
> gets
> >  the 'argument' attribute as parameter?
> >
> >  Or am i on some completely wrong track of how to do this?
> >
> >  kr. Lars Dam
> >
>

Re: Proper way to use a definition attribute as argument or parameter for an action?

Posted by Chris Pratt <th...@gmail.com>.
You can set the value of argument either using EL in the value=""
attribute, or using JSP in the body of the putAttribute tag.

Example:

  <tiles:insertTemplate template="/someminorjsppage.jsp">
     <tiles:putAttribute name="title" value="some.title.i18n.key"/>
     <tiles:putAttribute name="argument" value="${myArgument}"/>
  </tiles:insertTemplate>

  <tiles:insertTemplate template="/someminorjsppage.jsp">
     <tiles:putAttribute name="title" value="some.title.i18n.key"/>
     <tiles:putAttribute name="argument"><s:property
value="%{ognlValue}"/></tiles:putAttribute>
  </tiles:insertTemplate>

(*Chris*)

On Mon, Apr 28, 2008 at 5:30 AM, Lars Dam <la...@gmail.com> wrote:
> I am trying to make some kind of jsp 'component' page that can be reused
>  multiple times with different datasets on a single jsp page. When defining
>  the templates i use i can give some arguments that i can access on the
>  template page, but how can i use these arguments on the action?
>
>  If i have a jsp page that contains two templates like:
>  :
>  <tiles:insertTemplate template="/someminorjsppage.jsp">
>     <tiles:putAttribute name="title" value="some.title.i18n.key"/>
>     <tiles:putAttribute name="argument" value="someargument"/>
>  </tiles:insertTemplate>
>  :
>  <tiles:insertTemplate template="/someminorjsppage.jsp">
>     <tiles:putAttribute name="title" value="some.title.i18n.key"/>
>     <tiles:putAttribute name="argument" value="anotherargument"/>
>  </tiles:insertTemplate>
>  :
>
>  What would be the proper way to send the value of "argument" to the action,
>  so the action could use this to find data for the jsp page?
>
>  Would it be possible to have some kind of callback to the action that gets
>  the 'argument' attribute as parameter?
>
>  Or am i on some completely wrong track of how to do this?
>
>  kr. Lars Dam
>