Showing posts with label Struts. Show all posts
Showing posts with label Struts. Show all posts

Monday, May 4, 2020

[Struts][Resolved] Iterator get data from List Array

Suppose you have a source with DataType List<Equip> named equipStatusList.
and there are some field named "code" and "desciption".
<s:iterator value-"equipStatusList" status="statusTitle">
  <th width>
    <div onclick="javascript:toggleSort('${equipStatusList[statusTitle.index].code}')">
      <s:property value="equipStatusList[#statusTitle.index].desciption" />
      <s:if test="%{sortBy[0]==equipStatusList[#statusTitle.index].code}">
        <s:if test='%{sortOrder=="asc"}'>
          &uArr;
        </s:if>
        <s:else>
          &dArr;
        </s:else>
      </s:if>
    </div>
  </th>
</s:iterator>

Wednesday, April 29, 2020

[Struts][Example] Iterator get data from List

Suppose you have a source with DataType List<Equip> named equipStatusList.and there are some field named "code" and "description".
This is an example of the struts iterator used in view with Spring framework:
<s:iterator value="equipStatusList" status="statusTitle">
  <div onclick="javascript:toggleSort('${equipStatusList[statusTitle.index].code}')">
    <s:property value="equipStatusList[#statusTitle.index].desciption" />
    <s:if test="%{sortBy[0]==equipStatusList[#statusTitle.index].code}">
      <s:if test='%{sortOrder=="asc"}'>
        &uArr;
      </s:if>
      <s:else>
        &dArr;
      </s:else>
    </s:if>
  </div>
</s:iterator>
index is used for get index of each iterator item.
and than use this index number to access your List item.

Reference:

https://struts.apache.org/tag-developers/iterator-tag.html

Tuesday, April 28, 2020

[Struts][Example] Iterator get data from array

You can use <s:property> assess items of Iterator,
or use .index to know the index for assisting get the item value.
Here is an example supposing you have a source with DataType int[] array named statusCounts.
<s:iterator value="statusCounts" status="count">
  <s:if test='%{statusCounts[#count.index]>0}'>
    <s:property>
  </s:if>
  <s:else>
    &nbsp;
  </s:else>
</s:iterator>
Reference:
https://struts.apache.org/tag-developers/iterator-tag.html
https://stackoverflow.com/questions/19856296/to-access-the-index-value-of-struts-iterator-in-scriptlet-array-index