Iterate List of String in Tapestry
I am new to Tapestry 5, and I stuck with one of the following scenario :
Controller.java
@Property
private List<EnumeratedDynamicProperty> enumeratedDynamicPropertyList;
@Property
private EnumeratedDynamicProperty enumeratedDynamicPropertyInfo;
.tml
<tr t:type="Loop" t:source="enumeratedDynamicPropertyList" t:value="enumeratedDynamicPropertyInfo" encoder="encoder">>
<td>${enumeratedDynamicPropertyInfo.propertyName}</td>
<td>${enumeratedDynamicPropertyInfo.description}</td>
<td>${enumeratedDynamicPropertyInfo.type}</td>
</tr>
Now inside EnumertedDynamicProperty, I have one field with following definition :
private List<开发者_StackOverflowString> classNames = new ArrayList<String>();
Now I want to add one more <td>
at the tml file, and display the List values comma separated) there.
For example :
<td>
enumeratedDynamicPropertyInfo.getClassNames.get(0).get(0),enumeratedDynamicPropertyInfo.getClassNames.get(0).get(1)
</td>
Doing it as silb suggests is probably your best option. Should you want to do it in the template file, you could iterate through the list with another loop:
<td>
<span t:type="Loop" t:source="enumeratedDynamicPropertyInfo.classNames"
t:value="var:currentClassName">
${var:currentClassName}
</span>
</td>
You could use CSS to add the necessary commas in between elements to keep the template simple.
You could always create a method Controller.formatProperty that takes no argument and returns the formatted string. It can retrieve the current value of the property from the loop variable Controller.enumeratedDynamicPropertyInfo. Then call Controller.formatProperty from the tml file.
精彩评论