| example.application |
<application name="example">
<description>Example Application</description>
<library id="base" specification-path="/org/mb/tapestry/base/base.library"/>
<library id="checkboxes" specification-path="/org/mb/tapestry/checkboxes/checkboxes.library"/>
</application>
|
| Home.html |
<span jwcid="$content$">
<body jwcid="@Body">
<!-- Use of the If, Else, and For components outside a form -->
<span jwcid="@base:If" condition="true">The outer condition is true</span>
<span jwcid="@base:Else">The outer condition is false</span>
<table>
<tr jwcid="loop@base:For" source="ognl: { 'Red', 'Green', 'Blue' }">
<td><span jwcid="@Insert" value="ognl:components.loop.value"/></td>
</tr>
</table>
<br>
<hr>
<!-- Use of the If, Else, and For components inside a form -->
<!-- Hidden fields are automatically generated and stale links do not occur -->
<span jwcid="@Form">
<span jwcid="@base:If" condition="false">The inner condition is true</span>
<span jwcid="@base:Else">The inner condition is false</span>
<span jwcid="@checkboxes:CheckboxGroup">
<table>
<tr>
<th><span jwcid="@checkboxes:ControlCheckbox"/></th>
<th>Colors</th>
</tr>
<tr jwcid="cycle@base:For" source="ognl:colors" value="ognl:color" convertor="ognl:convertor">
<td><span jwcid="@checkboxes:ControlledCheckbox" selected="ognl:selected"/></td>
<td><span jwcid="@Insert" value="ognl:components.cycle.value"/></td>
</tr>
</table>
</span>
<span jwcid="@Submit"/>
</span>
</body>
</span>
|
| Home.page |
<page-specification class="org.mb.tapestry.test.Home">
<property-specification name="color" type="java.lang.String"/>
<property-specification name="colorSet" type="java.util.Set"
initial-value="new java.util.HashSet()"/>
</page-specification>
|
| Home.java |
package org.mb.tapestry.test;
import java.util.Random;
import java.util.Set;
import org.apache.tapestry.contrib.table.model.IPrimaryKeyConvertor;
import org.apache.tapestry.html.BasePage;
public abstract class Home extends BasePage implements IPrimaryKeyConvertor
{
public abstract String getColor();
public abstract Set getColorSet();
private String[] _colors;
protected void initialize() {
// shuffle the colors -- the For component should work fine even so
_colors = new String[] { "White", "Green", "Red" };
int len = _colors.length;
Random rand = new Random();
for (int i = 0; i < len; i++) {
int idx = rand.nextInt(len);
String color = _colors[i];
_colors[i] = _colors[idx];
_colors[idx] = color;
}
}
public String[] getColors()
{
return _colors;
}
public boolean isSelected()
{
return getColorSet().contains(getColor());
}
public void setSelected(boolean selected)
{
if (selected)
getColorSet().add(getColor());
else
getColorSet().remove(getColor());
}
public IPrimaryKeyConvertor getConvertor()
{
return this;
}
/**
* @see org.apache.tapestry.contrib.table.model.IPrimaryKeyConvertor#getPrimaryKey(java.lang.Object)
*/
public Object getPrimaryKey(Object objValue) {
return "XXX" + objValue;
}
/**
* @see org.apache.tapestry.contrib.table.model.IPrimaryKeyConvertor#getValue(java.lang.Object)
*/
public Object getValue(Object objPrimaryKey) {
return ((String) objPrimaryKey).substring(3);
}
}
|