次のようなコンボボックスがあります。
<rich:select id="foo" value="#{fooVo.selectedFoo}" defaultLabel="Please select one">
<f:selectItems value="#{fooVo.fooList}"/>
</rich:select>
リストからエントリを選択しようとしているときはいつでも、fooVo.selectedFoo
null です。fooVo.selectedFoo
そして、のセッターがコールされていないことがわかりました。
そして、ここに豆があります:
@ManagedBean(name="fooVo")
@SessionScoped
public class FooVo {
private List<SelectItem> fooList = new ArrayList<SelectItem>();
private String selectedFoo;
/** getter and setter **/
}
選択したエントリselectedFoo
を入力する必要があるとします。この問題を修正する方法を教えてください。
2012 年 8 月 15 日の更新 - fooList はどのように更新されますか?
リストの構成は DAO にあります。
public List<SelectItem> getFooList() {
List<SelectItem> newList = new ArrayList<SelectItem>();
Integer theValue = ...;
String theLabel = ...;
newList.add(new SelectItem(theValue.toString(), theLabel));
}
その後、newList
は BOC に戻り、ローカル変数によって保持されます。他の処理作業を行った後、次のnewList
ように別の ActionBean クラスに移動します。
public List<SelectItem> processFooList() {
...
List<SelectItem> theList = theDao.getFooList();
return theList;
}
ActionBean クラスでは、このリストは最終的にfooVo
Spring 依存性注入を介してマネージド Bean に到達します。
@ManagedBean(name="theAction")
@SessionScoped
public class ActionBean {
@ManagedProperty(value="#{fooVo}")
private FooVo fooVo;
public void setTheBo(IBoc theBo) {
this.theBoc = theBo;
this.FooVo.setFooList(theBo.processFooList());
}
}
ページがロードされたときに準備ができているようにするため、setter Spring DI 中にfooVo
の fooList を入力します。fooList