feng

飘逸~~~~~life

struts1迭代中区分奇偶列等情况的一种实现


在struts2中的迭代标签有直接的奇数偶数区分的办法
如下
<s:iterator value="#request.names" status="stuts">                
                
<s:if test="#stuts.odd == true">
                    
<li>White <s:property /></li>
                
</s:if>
                
<s:else>
                    
<li style="background-color:gray"><s:property /></li>
                
</s:else>
 
</s:iterator>
有了<s:if>标签的帮助和OGNL很容易就实现了,但是在struts1中如何实现这样一个功能呢?
struts1中有<logic:equal>标签,实际上它没有<s:if>好用,它需要一个bean或者一个变量
在struts1中没有OGNL,但是我们还有EL,借助与EL我们可以判断奇偶数
如${stuts%2==0} ,这个EL得到一个布尔值,我们也可以把它当string 来用
既然我们需要一个变量,那我们就先定义一个string变量,让它的值等于"true",
在利用<logic:equal>标签,我们就可以实现奇偶数的功能
具体代码如下:
 
<bean:define id="curId" value="true"/>
   
<logic:iterate id="number" indexId="stuts" name="numberlist">
                
               
     
<logic:notEqual name="curId" value="${stuts%2==0}">
              
    
<li>White ${number}</li>
                
</logic:notEqual>
 
<logic:equal name="curId" value="${stuts%2==0}">
             
<li style="background-color:gray">${number}</li>    
                
</logic:equal>
     
</logic:iterate>
实际上我们也可以借助于次逻辑实现其他一些页面表现方面的功能

posted on 2009-02-26 17:17 feng 阅读(1633) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: