我正在尝试使用 JSF 解决这里的一些问题,但我没有运气。我会尝试恢复我的代码,因为我不认为这里的很多代码可以帮助你解决这个问题,所以我会尝试更好地描述我的问题。
现在我有一个存储三个班次的字符串: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
*/
那么,基于这些事情,如果选择了 matutinal 复选框,我该如何选择 turnos[0],如果选择了vespertine复选框,我该如何选择 turnos[0],如果选择了每晚复选框,我该如何选择 turnos[2]?现在这不起作用,因为如果我先选择 Nightly,则位置 turnos[0] 将等于“nigthly”。
我该如何解决这个问题?