如何从primefaces解决selectManycheck中的错误?

时间:2017-09-28 14:50:59

标签: jsf primefaces enums selectmanycheckbox

我有一个页面的患者记录屏幕,其中有一个枚举以指示其状态是否为紧急,但是当它保存在数据库中时,它会在primefaces的selectmanycheckbox中给出错误。有人可以帮忙吗?谢谢

我的页面:

<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>

我的豆子

@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;
}

}

错误:

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

1 个答案:

答案 0 :(得分:-1)

使用SelectItem时,您无需指定属性...默认情况下也不需要collectionType。 尝试这样的事情:

<p:outputLabel value="Urgência" for="urgencia" />
<p:selectManyCheckbox id="urgencia" value="#{cadastroListaBean.espera.urgencia}"
                      converter="#{urgenciaConverter}" >
    <f:selectItems value="#{cadastroListaBean.urgencias}" var="urgencia" />
</p:selectManyCheckbox>