Tapestry - 广播组的动态属性

时间:2015-05-08 11:27:36

标签: java tapestry

我在一个无线电组元素上有一个循环。我想知道每个广播组的选择值。有没有办法动态生成值属性?

只有一个广播组才能正常工作。

我的.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;

由于

2 个答案:

答案 0 :(得分:0)

你可以使用tapestry-stitch的map:绑定前缀(demo here

然后你可以声明:

@Property
private Map<String, WaiverDetail> waiverDetailMap;

void onPrepareForSubmit() {
    waiverDetailMap = new LinkedHashMap<String, WaiverDetail>();
}

<t:radiogroup value="map:waiverDetailMap[waiverHeader.code]" encoder="waiverDetailEncoder">

答案 1 :(得分:0)

为了完整性,这可以在没有map:绑定前缀和自定义getter / setter的情况下实现。

TML

<t:loop source="waiverHeaders" value="waiverHeader">            
    <t:radiogroup value="selectedWaiverDetail" encoder="waiverDetailEncoder">

爪哇

@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);
}