Hi Ralf,

Thanks for the pointers. It feels to me that the having the param tag within an iterator was a bit of a hack in the first place. Some solutions I may play with...

1) create a params class that copes with collections
2) subclass the url class to cope with param maps directly
3) something else I have yet to think of :)

thanks again,
Nathan

Ralf Fischer wrote:
Hi Nathan,

On Wed, Jan 21, 2009 at 9:25 AM, Nathan Coast <nat...@codeczar.com> wrote:
Hi Dave,

Thanks for your tip.  Apologies for my newbie-ness.  Like I said, I've tried
every combination I can think of - except presumably the correct one.  Some
examples:

<s:param name="#attr['reqParam'].key"
       value="#attr['reqParam'].value"/>

<s:param name="#['reqParam'].key" value="#['reqParam'].value"/>

<s:param name="[0].key" value="[0].value"/>

<s:param name="#[reqParam].key" value="#[reqParam].value"/>

<s:param name="#[0].key" value="#[0].value"/>

               <s:param name="#attr.reqParam.key"
value="#attr.reqParam.value"/>

in conjunction with below, where reqParameters is a Map of key & value pairs
I'd like to add to the URL.

<s:url id="uri" action="%{action}" namespace="%{nameSpace}">
       <s:iterator var="reqParam" value="%{reqParameters}"
                       status="paramStatus">
               <s:param name="#attr['reqParam'].key"
                       value="#attr['reqParam'].value"/>
       </s:iterator>
</s:url>

Any hints as to the syntax I should use in the s:param tag?

The problem here is not the valid OGNL syntax. The embedded <s:param
/> inside the <s:iterator /> does not reach the outer <s:url /> tag,
as the Param looks out for the "next enclosing" Struts tag component,
which is the iterator in this case.

I worked my way around this issue by creating a new tag which
duplicates the behaviour of <s:param />, but looks for a certain type
of enclosing component. In this case it would be the URL component.

IMO this is a common problem and worth a fix.

In any case you may file a feature request implementing this in
Jira[1]. If I find the time I may  provide a patch for this later this
week. What I don't know is whether there are more cases where "outer"
struts tags need a variable number of "embedded" struts tag
invocations which is based on a collection or map, by utilizing the
iterator tag.

If you want to do it yourself you can take a look at the class
Param[2], subclass it and invoke the findAncestor method in
Component[3] with URL.class rather than Component.class in your new
subclass.

Bye,
-Ralf

[1] https://issues.apache.org/struts/secure/Dashboard.jspa
[2] 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Param.java?view=markup
[3] 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Component.java?view=markup


cheers,
Nathan


Dave Newton wrote:
Nathan Coast wrote:
Is passing a map of params to a construct a url supported by the URL tag?
(or some other struts2 mechanism).

<s:url id="uri" action="%{action}" namespace="%{nameSpace}">
   <s:iterator value="%{parameters}" status="paramStatus">
       <s:param name="%{key}" value="${value}"/>
   </s:iterator>
</s:url>

${key}  ${value} return the correct values however the s:param doesn't
support expressions.
It doesn't support JSP EL expressions, but it *does* support OGNL
expressions.

Dave


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



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



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




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

Reply via email to