2017-07-03 27 views
-1

我想在JSF中使用多個下拉選擇。這裏要說的是,我發現這個解決方案的代碼:使用java數組列表填充html選項

<select id="dates-field2" class="multiselect-ui form-control" 
             multiple="multiple"> 
     <option value="item1" >item1</option> 
     <option value="item2" >item2</option> 

</select> 

如何使用這個在JSF頁面,並填寫由數組列表選項在Java中,而不是物品1和ITEM2? 我在JSF中使用了f:selectItems,但它不起作用!

回答

0

你的例子只是純HTML。如果您希望JSF將其作爲輸出呈現,您需要使用h:selectManyListbox標記。它還提供了將集合傳遞給它的可能性,該集合呈現所有選項。

<h:selectManyListbox value="#{yourSelectedItemValue}"> 
     <f:selectItems value="#{yourCollection}" var="f" 
       itemLabel="#{f.yourItemLabel}" itemValue="#{f.yourItemValue}" /> 
</h:selectManyListbox> 

這會給你如何使用它的詳細信息: http://www.mkyong.com/jsf2/jsf-2-multiple-select-listbox-example/

+0

它就像一個列表,但我想用它作爲下拉菜單,可以選擇多個項目。 – bigelite

0

也許你在找H:selectManyMenu組件?與Ipper的解釋非常相似:

<h:selectManyMenu value="#{yourBean.selectedValues}"> 
    <f:selectItems value="#{yourBean.yourCollection}" var="item" 
     itemLabel="#{item.label}" itemValue="#{item.value}"/> 
</h:selectManyMenu>