【问题标题】:What is the strut 2 equivalent of strut 1 logic:iterate tag property attribute什么是strut 1逻辑的strut 2等价物:迭代标签属性
【发布时间】:2019-08-28 20:03:44
【问题描述】:

在 strut 1 中,我们使用 logic:iterate 标签来遍历列表。在定义这个标签时,我们使用property属性和strut 1调用这个属性的getter方法来获取Iterable Object。 strut 2中相同的东西是什么?

正如下面 strut 1 中的代码所示,我们使用 logic:iterate 标签来迭代可迭代对象。而Strut 1通过调用name属性(本例中为DataForm)定义的property属性(本例中为records)的getter方法得到这个itearble对象。

即在下面的示例中,strut 1 在内部调用了 DataForm 类中存在的 getRecords() 方法来获取可迭代对象。

我们如何在 strut 2 中实现相同的目标?

<div STYLE=" height: 300px; width: 860;font-size:12px; overflow: auto;">              
<html:form action="/discardHorisBulk.do" target="content">
      <table width="840">      
      **<logic:iterate id="horisList" name="DataForm" property="records" indexId="indexId" type="com.waghtech.client.isTech.model.Horis" >**
        <tr>
          <%
              String bgColor="#fffafa";
              int size = indexId.intValue();
              if (indexId.intValue() %2 == 0)
              {
                bgColor="#dcdcdc";
              }

              java.util.HashMap params = new java.util.HashMap();       

              params.put("key",  horisList.getKey() );
              params.put("clientName", horisList.getClientName() );
              pageContext.setAttribute("paramsName", params); 
          %>

           <td bgcolor=<%=bgColor%> width="200">
           <html:link page="/mapClient.do" name="paramsName" scope="page" >            
                <bean:write name="horisList" property="clientName"/>
           </html:link> 
           </td>
           <td bgcolor=<%=bgColor%> width="60">
               <bean:write name="horisList" property="startDate"/>
           </td>               

           <td bgcolor=<%=bgColor%> width="60">
               <bean:write name="horisList" property="endDate"/>
           </td>               
        <!-- 
            <td bgcolor=<%=bgColor%> width="200">
               <bean:write name="horisList" property="displayFd"/>
           </td>
            -->
           <td bgcolor=<%=bgColor%>  width="200">
               <bean:write name="horisList" property="userfileName"/>
           </td>               
           <td bgcolor=<%=bgColor%>  width="40">               
               <html:multibox name="dataForm" property="markedRecords" value="<%=horisList.getClientName()%>">    
                <bean:write name="horisList" property="key"/>  
               </html:multibox>
           </td>               
        </tr>   
    </logic:iterate>

    </table>
</div>

【问题讨论】:

  • 当你迭代时,当前对象被推到值栈的顶部,所以它的属性可以通过普通的 OGNL 访问。这在文档和许多教程/示例中都有讨论。

标签: struts2 struts


【解决方案1】:

你可以为它使用 value 属性。像这样:

 <ol>
<s:iterator value="records">
  <li><s:property value="userfileName"/></li>
</s:iterator>
</ol>

这将调用此列表的 getter 方法,并且当您使用 value 属性时,它将为记录类中的这些字段调用 getter。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-10
    • 1970-01-01
    • 2011-01-31
    • 1970-01-01
    • 1970-01-01
    • 2015-03-14
    相关资源
    最近更新 更多