0

I'm trying to get selected values from a selectCheckboxMenu using PrimeFaces 5.3 and JSF 2, but always the selection list is empty.

This is the HTML part:

<p:selectCheckboxMenu id="cours" value="#{etudiantController.checkedCours}"
    converter="#{coursConverter}" label="Liste cours available" multiple="true" 
    panelStyle="width:250px">
    <f:selectItems value="#{etudiantController.coursEtudiant}" var="coursEtd" 
        itemLabel="#{coursEtd.libelleCours}" itemValue="#{coursEtd.idCours}" />
</p:selectCheckboxMenu>

Bean part:

private List<Cours> checkedCours;

for(Cours coursToAdd : checkedCours){
    System.out.println("enter ... !!!");
    coursService.addCours(coursToAdd);
}

Converter :

public class CoursConverter implements Converter {

public Object getAsObject(FacesContext context, UIComponent component, String value) {
    if (value != null && !value.isEmpty()) {
        return component.getAttributes().get(value);
    }
    return null;
}

public String getAsString(FacesContext context, UIComponent component, Object value) {
    if (value == null) {
        return "";
    }
    if (value instanceof Cours) {
        Cours cours = (Cours) value;
        String name = cours.getLibelleCours();
        return name;
    } else {
        throw new ConverterException(new FacesMessage(value + " est un Cours non valide"));
    }
} }

The problem here is that it never enter in the block.

Any help? Thank you.

hmzn
  • 321
  • 2
  • 6
  • 22

1 Answers1

0

Try setting an Id to your converter and calling it using that id

@FacesConverter("coursConverter")
public class CoursConverter implements Converter {
    ...
}

--

<p:selectCheckboxMenu id="cours" value="#{etudiantController.checkedCours}"
    converter="coursConverter" label="Liste cours available" multiple="true" 
    panelStyle="width:250px">
    <f:selectItems value="#{etudiantController.coursEtudiant}" var="coursEtd" 
    itemLabel="#{coursEtd.libelleCours}" itemValue="#{coursEtd.idCours}" />

David Florez
  • 1,460
  • 2
  • 13
  • 26