<logic:iterate> tag solution needed

B

boss

<logic:iterate name="mybean" id="index" indexId="k">
if(k%2==0){
do somethng..
}
if(k%2==1){
do something..
}
</logic:iterate>


....How achieve this using struts tag?
i already achieve this using scriplet..so i dont want use scriplet..

and also tell me how to access a bean...defined in struts tag..

like if i want to use...index bean inside a scriplet.then hw to use?




Thanks
Anand
 
T

Tim Slattery

boss said:
<logic:iterate name="mybean" id="index" indexId="k">
if(k%2==0){
do somethng..
}
if(k%2==1){
do something..
}
</logic:iterate>


...How achieve this using struts tag?

How about JSTL?

<c:forEach items="mybean" var="index" varStatus="stat">
<c:select>
<c:when test="${stat.count %2 == 0}">
stuff for even row
<c:\when>
<c:eek:therwise>
stuff for odd row
<c:\otherwise>
</c:select>
</c:forEach>
 
B

boss

How about JSTL?

<c:forEach items="mybean" var="index" varStatus="stat">
<c:select>
<c:when test="${stat.count %2 == 0}">
stuff for even row
<c:\when>
<c:eek:therwise>
stuff for odd row
<c:\otherwise>
</c:select>
</c:forEach>



Thanks Tim..

But I need to iterate over a Hashmap..
In which I am having a bean,contains properties like..name and
hashmap.

So i have to use <foreach> inside a <foreach>...

and also inside the condition i need to make use of the bean
properties.

One more think..

can't we use expression language inside struts tag?..

like below

<bean:define id="mybean" value="${(k%2)==0}"/>

currently i am trying to use like this but its not working...

do u know any other way of implementing this..


Once again thank u..
 
T

Tim Slattery

boss said:
Thanks Tim..

But I need to iterate over a Hashmap..
In which I am having a bean,contains properties like..name and
hashmap.

So i have to use <foreach> inside a <foreach>...

You can nest forEach loops
and also inside the condition i need to make use of the bean
properties.

One more think..

can't we use expression language inside struts tag?..

like below

<bean:define id="mybean" value="${(k%2)==0}"/>

Yes. If your servlet container supports servlets 2.4, then this is no
problem at all. Servlets 2.4 allows you to put EL anyplace in your JSP
page. If you're using an earlier container (like WebLogic 2.8, which
we're just now transitioning off of), you can use the Struts EL
libraries, which come with the Struts package.
 
J

Jason.Herald

<logic:iterate name="mybean" id="index" indexId="k">
if(k%2==0){
do somethng..}

if(k%2==1){
do something..}

</logic:iterate>

...How achieve this using struts tag?
i already achieve this using scriplet..so i dont want use scriplet..

and also tell me how to access a bean...defined in struts tag..

like if i want to use...index bean inside a scriplet.then hw to use?

Thanks
Anand

I did it by using a property in the bean, for example:
<div class='<bean:write name="rotateColor" property="colorClass" />'>

rotateColor is loaded as a class and passed in through request and is
defined as such:

private String colorClass = "even";

public String getColorClass() {
colorClass = colorClass.equals("odd") ? "even" : "odd";
return colorClass;
}

public void setColorClass(String colorClass) {
this.colorClass = colorClass;
}
 
B

boss

You can nest forEach loops






Yes. If your servlet container supports servlets 2.4, then this is no
problem at all. Servlets 2.4 allows you to put EL anyplace in your JSP
page. If you're using an earlier container (like WebLogic 2.8, which
we're just now transitioning off of), you can use the Struts EL
libraries, which come with the Struts package.

I am using servlet 2.4...only still it is not working..then
I did google n found that we can't use a customtags as customtag
attributes..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top