I have a patient record screen of a page in which it has an enum to indicate if its status is urgent, but it is giving error in the selectmanycheckbox of the primefaces when it is saved in the database. Can anyone help? Thank you
My page:
<p:outputLabel value="Nome" for="nomepa" />
<p:autoComplete id="nomepa" size="40" dropdown="true"
value="#{cadastroListaBean.espera.paciente}"
completeMethod="#{cadastroListaBean.completarPaciente}"
var="paciente" itemLabel="#{paciente.nome}" itemValue="#{paciente}"
forceSelection="true">
<p:ajax event="itemSelect" process="@this"
update="frmCadastroLista"
listener="#{cadastroListaBean.completarCampo}" />
</p:autoComplete>
<p:outputLabel value="Urgência" for="urgencia" />
<p:selectManyCheckbox id="urgencia"
value="#{cadastroListaBean.espera.urgencia}"
converter="#{urgenciaConverter}" >
<f:selectItems value="#{cadastroListaBean.urgencias}"
var="urgencia" itemValue="#{urgencia}"
itemLabel="#{urgencia.descricao}" />
<f:attribute name="collectionType" value="java.util.ArrayList" />
</p:selectManyCheckbox>
My Bean
@Named
@ViewScoped
public class CadastroListaBean implements Serializable {
private static final long serialVersionUID = 1L;
public void salvar() {
this.espera = cadastroListaService.salvar(this.espera);
}
public List<SelectItem> getUrgencias() {
List<SelectItem> listUrgencias = new ArrayList<SelectItem>();
for (Urgencia ug : Urgencia.values()) {
listUrgencias.add(new SelectItem(ug, ug.getDescricao()));
}
return listUrgencias;
}
}
My Enum:
public enum Urgencia {
SIM("Sim"),
NAO ("Não");
private String descricao;
Urgencia(String descricao) {
this.descricao = descricao;
}
public String getDescricao() {
return descricao;
}
}
The error:
Caused by: javax.faces.FacesException: Target model Type is no a Collection or Array at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValuesForModel(MenuRenderer.java:391) at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValue(MenuRenderer.java:128) at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:314) at org.primefaces.component.selectmanycheckbox.SelectManyCheckboxRenderer.getConvertedValue(SelectManyCheckboxRenderer.java:39) at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1034) at javax.faces.component.UIInput.validate(UIInput.java:964) at javax.faces.component.UIInput.executeValidate(UIInput.java:1237) at javax.faces.component.UIInput.processValidators(UIInput.java:702) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1220) at javax.faces.component.UIForm.processValidators(UIForm.java:253) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1220) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1220) at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1164) at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76) ... 53 more
You do not need to specify properties, when using
SelectItem
s... Also nocollectionType
is necessary by default. Try something like this: