导航

logic:equal

Posted on 2008-06-26 11:06  lirengang  阅读(2329)  评论(0)    收藏  举报
<%
           HashMap h = new HashMap();
           String vegetables[] = {"pepper","cucumber"};
           String fruits[] = {"apple","orange","banana","cherry","watermelon"};
           String flowers[] = {"chrysanthemum","rose"};
           String trees[] = {"willow"};
          
           h.put("Vegetables", vegetables);
           h.put("Fruits",fruits);
           h.put("Flowers",flowers);
           h.put("Trees",trees);
           request.setAttribute("catalog",h);
    %>
    <logic:iterate id="cat" name="catalog">
        <logic:equal name="cat" property="key" value="Vegetables">
            <tr>
                 <td>      
                     Vegetables
                </td>
           </tr>
       </logic:equal>
    </logic:iterate>


<logic:equal name="map" property="key" value="${list.moduleId}">
      <td>     
          <html:multibox property="powersId" value="${list.powerId}">
          </html:multibox>
          <bean:write name="list" property="powerChinese"/>
     </td>
 </logic:equal>
 如果map的属性key值为${list.moduleId},则执行:
     <td>     
          <html:multibox property="powersId" value="${list.powerId}">
          </html:multibox>
          <bean:write name="list" property="powerChinese"/>
     </td>




一是定义新字符串常量:

<bean:define id="foo" value="This is a new String"/>
<bean:define id="bar" value='<%= "Hello, " + user.getName() %>'/>
<bean:define id="last" scope="session" value='<%= request.getRequestURI() %>'/>


二是复制一个现有的bean给新的bean:

<bean:define id="foo" name="bar"/>
<bean:define id="baz" name="bop" type="com.mycompany.MyClass"/> //定义脚本变量的类型,默认为Object


三是复制一个现有的bean的属性给新的bean:

<bean:define id="bop" name="user" property="role[3].name"/>
<bean:define id="foo" name="bar" property="baz" scope="request" toScope="session"/>
//toScope属性指新bean的scope,默认为page

上段代码的意思是把名为bar的bean的baz属性赋值给foo,foo的类型为String(默认)。



<html:select       property="personnelId">         
             <html:option   value="">请选择</html:option>         
             <html:options collection="personList"  property="personId"   labelProperty="personName"/>             
</html:select>        
      html:options自动帮你迭代personList中的内容,前提是personList是Collection类型的,而且封装的是一个包含personId,personName属性的对象        
      property显示的是value,labelProperty显示的是页面看到的内容