You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ransika de Silva <ra...@gmail.com> on 2009/03/13 06:29:31 UTC

S:Iterator break out of it according to a condition

Hello all,
I have a list to iterate and according to a certain logic I want the
iteration to stop and break out of the iteration. Similar to the break in
java inside a loop. Any idea how I can achieve this?

Regards,

Ransika

Re: Struts Iterator tag and OGNL

Posted by Windy Hung <wi...@yahoo.com>.
Hi Wes,
 The solution you provided works.
 Thanks

 Windy Hung



________________________________
From: Wes Wannemacher <we...@wantii.com>
To: Struts Users Mailing List <us...@struts.apache.org>
Sent: Sunday, March 15, 2009 8:11:34 AM
Subject: Re: Struts Iterator tag and OGNL

On Sunday 15 March 2009 10:35:48 Windy Hung wrote:
> Hello,
> I want to check a property value with a class constant inside iterator tag.
> For example, I have a list data type object "products" and I use
> <s:iterator value="products"> to loop through it., Inside the looping, I
> want to use <s:if test tag to test if the variable "productName" of a
> product from products list equals to a class constant variable , for
> example, com.abc.product.ProductConstant.LABEL. Or if <s:property value can
> do the checking? Can any one help me how to use OGNL to do the checking?
>
> Thanks
>
> Windy Hung

<s:iterator value="products" var="prod">
<s:if test="#prod.prouctName.equals(@com.abc.product.ProductConstant@LABEL)">

</s:if>
</s:iterator>

The key here is using the @ sign to access statics. 
http://struts.apache.org/2.x/docs/ognl-basics.html#OGNLBasics-
Accessingstaticproperties

Also note that I'm assuming the productName is a variable of a type that 
sports a .equals() method that will work when passed the LABEL. Basically, I'm 
not assuming it's a string. If it is a string comparison, you can probably use 
eq or == or whatever works on strings.

-Wes
-- 

Wes Wannemacher
Author - Struts 2 In Practice 
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher


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


      

Re: Struts Iterator tag and OGNL

Posted by Wes Wannemacher <we...@wantii.com>.
On Sunday 15 March 2009 10:35:48 Windy Hung wrote:
> Hello,
> I want to check a property value with a class constant inside iterator tag.
> For example, I have a list data type object "products" and I use
> <s:iterator value="products"> to loop through it., Inside the looping, I
> want to use <s:if test tag to test if the variable "productName" of a
> product from products list equals to a class constant variable , for
> example, com.abc.product.ProductConstant.LABEL. Or if <s:property value can
> do the checking? Can any one help me how to use OGNL to do the checking?
>
> Thanks
>
> Windy Hung

<s:iterator value="products" var="prod">
<s:if test="#prod.prouctName.equals(@com.abc.product.ProductConstant@LABEL)">

</s:if>
</s:iterator>

The key here is using the @ sign to access statics. 
http://struts.apache.org/2.x/docs/ognl-basics.html#OGNLBasics-
Accessingstaticproperties

Also note that I'm assuming the productName is a variable of a type that 
sports a .equals() method that will work when passed the LABEL. Basically, I'm 
not assuming it's a string. If it is a string comparison, you can probably use 
eq or == or whatever works on strings.

-Wes
-- 

Wes Wannemacher
Author - Struts 2 In Practice 
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher


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


Struts Iterator tag and OGNL

Posted by Windy Hung <wi...@yahoo.com>.
Hello,
I want to check a property value with a class constant inside iterator tag.
For example, I have a list data type object "products" and I use <s:iterator value="products"> to loop through it.,
Inside the looping, I want to use <s:if test tag to test if the variable "productName" of a product from products list equals to a class constant variable , for example, com.abc.product.ProductConstant.LABEL. Or if <s:property value can do the checking?
Can any one help me how to use OGNL to do the checking?

Thanks

Windy Hung