0

次のようなコンボボックスがあります。

<rich:select id="foo" value="#{fooVo.selectedFoo}" defaultLabel="Please select one">
  <f:selectItems value="#{fooVo.fooList}"/>
</rich:select>

リストからエントリを選択しようとしているときはいつでも、fooVo.selectedFoonull です。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 クラスでは、このリストは最終的にfooVoSpring 依存性注入を介してマネージド 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

4

0 に答える 0