如何使用 <s:iterator> 从单个集合中绘制多个 HTML 表?

How to draw multiple HTML Tables from a single Collection with <s:iterator>?

假设我有两张桌子,星期一和星期二。我想根据对象的 属性 填充这些表。因此:

<s:iterator value="trainings">
 <table>
   <tr><th>Monday</th></tr>

   <s:if test="weekday.toString().equals('MONDAY')">
     <tr>
       <td>
          <s:property value="title" />
       </td>
    </tr>
   </s:if>
 </table>

 <table>
   <tr><th>Tuesday</th></tr>

   <s:if test="weekday.toString().equals('TUESDAY')">
     <tr>
       <td>
          <s:property value="title" />
       </td>
    </tr>
   </s:if>
 </table>

</s:iterator>

我怎样才能让它正常工作?谢谢

编辑:

public class Training {    
    private Weekday weekday;        
    ....        
}

public Enum Weekday {        
    MONDAY,
    TUESDAY,
    ...        
}

要从单一来源填充两个不同的表(在操作中拆分服务器端应该更好),您通常需要迭代集合两次:

    <table>
        <tr><th>Monday</th></tr>
  <s:iterator value="trainings">
      <s:if test="weekday.toString().equals('MONDAY')">
        <tr><td><s:property value="title" /></td></tr>
      </s:if>
  </s:iterator>
    </table>

    <table>
        <tr><th>Tuesday</th></tr>
  <s:iterator value="trainings">
      <s:if test="weekday.toString().equals('TUESDAY')">
        <tr><td><s:property value="title" /></td></tr>
      </s:if>
  </s:iterator>
    </table>

为避免多次执行<s:if>,您可以使用OGNL's List Selection:

    <table>
        <tr><th>Monday</th></tr>
  <s:iterator value="trainings.{? #this.weekday.toString() == 'MONDAY' }">
        <tr><td><s:property value="title" /></td></tr>
  </s:iterator>
    </table>

    <table>
        <tr><th>Tuesday</th></tr>
  <s:iterator value="trainings.{? #this.weekday.toString() == 'TUESDAY' }">
        <tr><td><s:property value="title" /></td></tr>
  </s:iterator>
    </table>

这会产生更小更清晰的 HTML 代码。