0

I have seleconeradio, for example:

<h:selectOneRadio value="#{myBean.selectedValue}" layout="pageDirection">
    <f:selectItems value="#{myBean.myList}" var="a" itemValue="#{a}" itemLabel="#{a}"/>
</h:selectOneRadio>

where myList is list of integers, e.g. 1,3,2,4. If user selects second element (i.e. 3) I want in myBean selectedValue to be 2, so I want to get index of selectItems item.

What should I write in f:selectItems itemValue tag? Or it is impossible?

P.S. I can do it by creating a new class in which I have the index property and create a new list of that class, giving the right index. But it is very bad solution.

4

2 に答える 2

0

indexOf(Object o)を使用する必要があります ..このリストで指定された要素が最初に出現したインデックスを返すか、このリストに要素が含まれていない場合は-1を返します...コードはおそらく次のようになります..

int index  = myList.indexof(selectedValue);
于 2014-05-06T04:50:54.300 に答える