ラジオボタンをBooleanで管理、表示をラベルで

意外と調べても載っていないんですね。。。
みんな困ってないんでしょうか?
Web的には良くあることだと思うんですが。


やりたいことは、

ラジオボタン+ラベルで表示(男/女 みたいな)
・管理はBooleanで。確認画面での表示は文字列で行いたい

ということ。


s2jsf-exampleで試しました。


employeeEdit.html

<tr>
<td class="label">testRadio</td>
<td>
<input checked="checked" id="testRadio1" value="1" name="testRadio" type="radio" m:passthrough="true" class="right"/>テスト1
<input id="testRadio2" value="0" name="testRadio" type="radio" m:passthrough="true" class="right"/>テスト2
</td>
</tr>
*1


employeeConfirm.html

<tr>
<td class="label">testReadio</td>
<td><span m:value="#{employeeDto.testRadioStr}"></span></td>
</tr>


EmployeeDto.java

// TODO 初期化はコンストラクタでやったほうが良いか?
private Boolean testRadio = false;
private String testRadioStr;
private Map testMap;

public String getTestRadioStr()
{
return (String)this.testMap.get(testRadio);
}
*2


EmployeeEditActionImpl.java

private Boolean testRadio;

public void setTestRadio(Boolean radio)
{
this.employeeDto.setTestRadio(radio);
}


app.dicon


<component name="testMap" class="java.util.LinkedHashMap">
<initMethod name="put">
<arg>true</arg>
<arg>"テスト1"</arg>
</initMethod>
<initMethod name="put">
<arg>false</arg>
<arg>"テスト2"</arg>
</initMethod>
</component>


・・・これで出来たけど、もうちょっといい方法ないですかね?

*1:"checked..."の部分は要修正。今のままだと確認画面から戻ってきても必ずテスト1にチェックがついた状態になってしまう

*2:testrRadioはsetter / getterが必要。testMapはsetterが必要

指定されたもの以外のプロパティ名をth、値をtdとしてテーブル表示する

とあるデータの詳細画面にて、あるDtoに格納されているプロパティ値を、
プロパティ名をthとして表示したい。


BeanUtils#describeで指定したDto内部の
propertyをMapで返してくれます。


あとは、表示したくないプロパティ値を
diconにでも記述してあげて、それ以外のもので
Listを形成してあげればOKでしょう。


今回の場合、プロパティ名も管理しなければ
ならないから、html側はどうなるんでしょうかね?
そこまではまだ試してない。


Map<プロパティ名, 値>でDtoListを作成しておいて、
html側で取り出せばよい?


Mapから取得する方法ってhtmlにどう書けばいいんだっけ?
思い出すのに時間かかりそう。。。