2017-02-07 1 views
1

JSFタグh:selectManyListboxを使用して、Beanからの項目のリストを表示します。JSF selectManyListboxは値バインディングのエラーを表示します

<h:selectManyListbox value="#{settingsBean.statusIds}" style="width: 100%; height: 200px;"> 
    <f:selectItem value="#{settingsBean.statusItems}" /> 
</h:selectManyListbox> 

statusItemsオブジェクトは、次のBeanクラスで定義されています

SettingsBean.javaこれをロードするときに

public class SettingsBean { 
    private List<String> statusIds; 
    private List<SelectItem> statusItems; 

    public SettingsBean() { 
     initStatus(); 
    }  

    private void initStatus() { 
     statusItems = new ArrayList<SelectItem>(); 

     statusItems.add(new SelectItem("v1", "lbl1")); 
     statusItems.add(new SelectItem("v2", "lbl2")); 
     statusItems.add(new SelectItem("v3", "lbl3")); 
    } 

    public ArrayList getStatusItems(){ 
     return getStatusItemsList(false); 
    } 

    @SuppressWarnings("unchecked") 
    private ArrayList getStatusItemsList(boolean selected) { 
     ArrayList ids = new ArrayList();  
     if (!selected) { 
      boolean inSelIds = false; 
      for (int i=0; i < statusItems.size(); i++) { 
       inSelIds = false; 
       SelectItem item = (SelectItem)statusItems.get(i); 

       if (selected==inSelIds) { 
        String text = item.getLabel();     
        //ids.add(text); 
        ids.add(new SelectItem(item.getValue(), text)); 
       } 
      } 
     } 

     return ids; 
    } 
} 

しかし、私はエラーメッセージを取得しています


HTTP Status 500 - java.lang.IllegalArgumentException: Value binding '#{settingsBean.statusItems}' of UISelectItem : {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /jsp/Settings.jsp][Class: javax.faces.component.html.HtmlSelectManyListbox,Id: _id3][Class: javax.faces.component.UISelectItem,Id: _id4]} does not reference an Object of type SelectItem 

この問題は何が原因で発生するのでしょうか?あなたの助けをありがとう

+0

それはあなたの代わりに他の –

答えて

0

JSFには、異なる2種類のタグselectItemselectItemsがあります。 selectItemは単一項目を表示するために使用されますが、複数の値を表示するには複数のselectItemタグを使用できます。しかし、selectItemsのリストがある場合は、selectItemではなくselectItemsを使用する必要があります。だから、以下のようなselectItemsであなたのXHTMLにselectItemタグを置き換える:

<h:selectManyListbox value="#{settingsBean.statusIds}" style="width: 100%; height: 200px;"> 
    <f:selectItems value="#{settingsBean.statusItems}" /> 
</h:selectManyListbox> 
+0

@NJサンフランシスコのデータの種類を使用しているオブジェクトの問題のタイプです:あなたはstatusIds用セッター/ゲッターを生成しています? – proudandhonour

+0

これは今動作します。私は助けに感謝します! – Junior

-1

あなたのバインディングはあまり正しくありません。あなたは例のように、コレクションまたは配列のいずれかを使用する必要がある。この場合:

<f:selectItem itemValue="#{settingsBean.statusItems}" /> 
https://www.tutorialspoint.com/jsf/jsf_selectmanylistbox_tag.htm

あなたはに

<f:selectItem value="#{settingsBean.statusItems}" /> 

から値=「value」属性を置き換える検討すべきであるほか

関連する問題