Hi everybody,

One of my programmer asked me the following:


I try to set the current value of a s:iterator in the "onclick" of a "s:a"
tag, but it doesn't work. How can I do this?

I know that I can't use something like overlapping tags: 

<s:iterator value="nbPages">
        <s:a href="#" onclick="javascript:refresh(<s:property />);return
false;"><s:property /></s:a>
</s:iterator>

Here, I put <s:property /> inside onclick attribute, the output is:
# 1 

(not very surprising...)


Since I resolved his problem while starting to write this question in the
Struts forum, I'll nevertheless send the solution, in the case other new
users of Struts 2 have the question.


The solution is to use use OGNL (or EL, expression language, if your JEE
version is 4 or 5): 

<s:iterator value="nbPages">
        <s:a href="#" onclick="javascript:refresh(%{top});return
false;"><s:property /></s:a>
</s:iterator>

"top" represent the current element of the iterator. It is a keyword in
OGNL/Struts 2 (correct me if I'm wrong).

Cheers,
Cyril Gambis
-- 
View this message in context: 
http://www.nabble.com/-Resolved---S2--Setting-current-value-of-an-iterator-inside-%22onClick%22-of-a-%22s%3Aa%22-tag-tf4427467.html#a12630101
Sent from the Struts - User mailing list archive at Nabble.com.


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

Reply via email to