Tapestry - 无线电组的动态属性
Tapestry - Dynamic properties for radio groups
我在单选组元素上有一个循环。我想知道每个无线电组有哪个选定值。有没有办法动态生成值属性?
当只有一个广播组时,它工作正常。
我的 .tml 文件:
<t:loop source="mapWaiverHeaderWithDetails.keySet()"
value="waiverHeader" t:id="mapWaiverHeader">
<div id="waivers_${waiverHeader.code}"
class="panel-collapse collapse in">
<div id="primary" class="panel-body editable">
<t:radiogroup value="selectedWaiverDetail" encoder="waiverDetailEncoder">
<ul>
<t:loop source="waiverDetails" value="waiverDetail">
...
</t:loop>
</ul>
</t:radiogroup>
</div>
</div>
</t:loop>
我的 .java 文件:
@Property
private WaiverDetail selectedWaiverDetail;
谢谢
您可以使用 tapestry-stitch 中的 map:
绑定前缀(演示 here)
那么你可以声明:
@Property
private Map<String, WaiverDetail> waiverDetailMap;
void onPrepareForSubmit() {
waiverDetailMap = new LinkedHashMap<String, WaiverDetail>();
}
和
<t:radiogroup value="map:waiverDetailMap[waiverHeader.code]" encoder="waiverDetailEncoder">
为了完整起见,没有 map:
绑定前缀和自定义 getter / setter.
也是可以实现的
TML
<t:loop source="waiverHeaders" value="waiverHeader">
<t:radiogroup value="selectedWaiverDetail" encoder="waiverDetailEncoder">
Java
@Property
private WaiverHeader waiverHeader;
@Property
private Map<String, WaiverDetail> waiverDetailMap;
@OnPrepareForRender
void onPrepareForRender() {
waiverDetailMap = lookupMapFromDatabase();
}
@OnPrepareForSubmit
void onPrepareForSubmit() {
waiverDetailMap = new LinkedHashMap();
}
public WaiverDetail getSelectedWaiverDetail() {
return waiverDetailMap.get(waiverHeader.getCode());
}
public void setSelectedWaiverDetail(WaiverDetail detail) {
waiverDetailMap.put(waiverHeader.getCode(), detail);
}
我在单选组元素上有一个循环。我想知道每个无线电组有哪个选定值。有没有办法动态生成值属性?
当只有一个广播组时,它工作正常。
我的 .tml 文件:
<t:loop source="mapWaiverHeaderWithDetails.keySet()"
value="waiverHeader" t:id="mapWaiverHeader">
<div id="waivers_${waiverHeader.code}"
class="panel-collapse collapse in">
<div id="primary" class="panel-body editable">
<t:radiogroup value="selectedWaiverDetail" encoder="waiverDetailEncoder">
<ul>
<t:loop source="waiverDetails" value="waiverDetail">
...
</t:loop>
</ul>
</t:radiogroup>
</div>
</div>
</t:loop>
我的 .java 文件:
@Property
private WaiverDetail selectedWaiverDetail;
谢谢
您可以使用 tapestry-stitch 中的 map:
绑定前缀(演示 here)
那么你可以声明:
@Property
private Map<String, WaiverDetail> waiverDetailMap;
void onPrepareForSubmit() {
waiverDetailMap = new LinkedHashMap<String, WaiverDetail>();
}
和
<t:radiogroup value="map:waiverDetailMap[waiverHeader.code]" encoder="waiverDetailEncoder">
为了完整起见,没有 map:
绑定前缀和自定义 getter / setter.
TML
<t:loop source="waiverHeaders" value="waiverHeader">
<t:radiogroup value="selectedWaiverDetail" encoder="waiverDetailEncoder">
Java
@Property
private WaiverHeader waiverHeader;
@Property
private Map<String, WaiverDetail> waiverDetailMap;
@OnPrepareForRender
void onPrepareForRender() {
waiverDetailMap = lookupMapFromDatabase();
}
@OnPrepareForSubmit
void onPrepareForSubmit() {
waiverDetailMap = new LinkedHashMap();
}
public WaiverDetail getSelectedWaiverDetail() {
return waiverDetailMap.get(waiverHeader.getCode());
}
public void setSelectedWaiverDetail(WaiverDetail detail) {
waiverDetailMap.put(waiverHeader.getCode(), detail);
}