我試圖用JSF解決一些問題,但我沒有運氣。我將嘗試恢復我的代碼,因爲我認爲這裏沒有很多代碼可以幫助您解決此問題,所以我會盡力描述更好的問題。如何將selectItems設置爲給定的字符串位置?
現在我有一個存儲三班倒的字符串:matutinal,vespertine和nightly。在我的架構中,我需要需要即myStringArray[0] = 'matutinal'
,myStringArray[1] = 'vespertine'
和myStringArray[3] = 'nightly'
。
我在我的應用程序中使用JSF 2.0和Primefaces - 也有一些omnifaces。
以下是我的JSF代碼:
<p:selectManyCheckbox value="#{escolaMBean.turnos}">
<f:selectItems value="#{escolaMBean.listaTodosTurnos}" var="turno" itemValue="#{turno.nome}" itemLabel="#{turno.nome}" />
</p:selectManyCheckbox>
注意在escolaMBean:
// Stores the selected "Turnos" (This means "shift" in English)
String[] turnos = new String[3];
// Stores all the "Turnos" received from DB
ArrayList<Turno> listaTodosTurnos = <myControl.myDbRequest()>
/*
* Turno have a simple ID and Name, in DB we have 3 "Turnos": Matutinal, Vespertine, Nightly
* In this MBean I have all getters and setters - and in "Turno" class too.
* When I set one string in turnos[n], this set the right value
*/
因此,基於這些事,我怎麼能選擇turnos [0]如果選擇黎明覆選框,turnos 1如果選擇了vespertine複選框,並且如果選擇夜間複選框,則回車[2]?現在這不起作用,因爲如果我首先選擇Nightly,那麼position turnos [0]將等於「nigthly」。
我怎樣才能解決這個問題呢?
再次感謝BalusC。我做了一些改編,但是這有效! – Paladini
不客氣。 – BalusC