Can't get s:set to work inside s:iterator

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Can't get s:set to work inside s:iterator

tristan_colson
Why doesn't this work:

<s:iterator value="%{messageTexts}" status="texts" id="theMessage">

<s:set name="oneLine" value='<s:property />' />
DEBUG: oneLine is: <s:property  value="#oneLine" /><br/>
DEBUG: oneLine2 is: <s:property  value="${#oneLine}" /><br/>
DEBUG: oneLine3 is: <s:property  value="${oneLine}" /><br/>

</s:iterator>

My debug never prints anything for oneMessage. I have tried various combinations of using %{} and not,
but I never get a value. What is it that I don't understand about s:set?

Reply | Threaded
Open this post in threaded view
|

Re: Can't get s:set to work inside s:iterator

DustFrog
What are you ultimately wanting to do here?  I can't follow the logic with the line that is listed in your code example:

<s:set name="oneLine" value='<b><s:property />' />
Reply | Threaded
Open this post in threaded view
|

Re: Can't get s:set to work inside s:iterator

tristan_colson
<s:property /> is one element of messageTexts (the array over which I am iterating).
I am trying to give it a name, using s:set.

However, I must not be understanding how to use s:set, since I am not getting anything when I try to display the new variable.

Note that if I do this:

DEBUG: <s:property /><br/> 

I do get the element of messageTexts displayed.
Reply | Threaded
Open this post in threaded view
|

Re: Can't get s:set to work inside s:iterator

DustFrog
Oh, ok.  Sorry.  Completely forgot how that worked since I don't use that approach.

How about trying something like this:

<s:iterator value="%{messageTexts}" status="texts" id="theMessage">
     <s:set name="oneLine" value="#theMessage" />
     DEBUG: oneLine is: <s:property  value="#oneLine" /><br/>
</s:iterator> 

NOTE:  In my testing, I didn't have to use %{} around my "value" in the s:iterator tag.  Just copying it as you had it in your previous example.
Reply | Threaded
Open this post in threaded view
|

Re: Can't get s:set to work inside s:iterator

tristan_colson
Heh.
You are quite correct, this does work.
However, I was trying to avoid using the "id" value, because I am seeing something weird about its behaviour.
messageTexts is an array with 5 elements, the first one is a string and the next 4 are null.

The iterator correctly goes through all 5 elements, but in all 5 cases, #theMessage is equal to the String in the first element. It apparently doesn't get cleared out once it has a non-null value.

That is why I was trying to use <s:property /> instead. It correctly reflects the null value of the last 4 elements.

What I am heading for is this:

<s:iterator value="%{messageTexts}" status="texts" id="theMessage">

   <s:if test="SOME TEST THAT WILL FIGURE OUT IF THE ELEMENT IS NOT NULL" >
       display the element
   </s:if>
</s:iterator> 

This is probably worthy of a separate thread, since it is really a different topic.
Would much appreciate help if you have any ideas.
Reply | Threaded
Open this post in threaded view
|

Re: Can't get s:set to work inside s:iterator

DustFrog
How about adding a default to the property like so:

<s:property  value="#oneLine" default="" /> or <s:property  value="#oneLine" default="--" />

Does that work?
emm
Reply | Threaded
Open this post in threaded view
|

Re: Can't get s:set to work inside s:iterator

emm
In reply to this post by DustFrog
Thanks it works for me!!