SelectOneRadio returns always 0

86 views Asked by At

I am developing a web application with JSF and EJB 3.1, I want to retrieve a value from a selectOneRadio :

<p:selectOneRadio id="noteItem" value="#{entretienController.val1}">
                                    <f:selectItem itemLabel="0" itemValue="0"/>
                   itemLabel="1" itemValue="1"/>
                                    <f:selectItem itemLabel="2" itemValue="2"/>
                                    <f:selectItem itemLabel="3" itemValue="3"/>
                                    <f:selectItem itemLabel="4" itemValue="4"/>
                                    <p:ajax process="@this" update="noteItem"/>
                                </p:selectOneRadio>
<p:commandButton process="entretienAnnuelDAPanel" action="#{noteEntretienController.testPersist()}" 
/>

testPersist method :

 public void testPersist() {
    System.out.println("entrée dans la méthode testPersist");
    try {
        getFacade().saveListeNoteEntretien();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        System.out.println("finally !!!!!");
    }

}

saveListeNoteEntretien method :

public void saveListeNoteEntretien() {
    List<NoteEntretien> listNoteEntretien = new ArrayList<>();
    try {
        Collaborateur collaborateur = collaborateurFacade.find(1);

        List<Competence> competences = null;
        Competence competence = new Competence();
        competences = competenceFacade.findAll();
        Integer maxIdEntretien = (Integer) em.createQuery("SELECT MAX(e.idEntretien) from Entretien 
   e").getSingleResult();
        Entretien entretien = new Entretien(maxIdEntretien + 1);
        entretien.setDateEntretien(new Date());
        entretien.setDiagnosticEntretien(entretienController.getDiagItem());
        entretien.setObservationsEntretien(entretienController.getObsItem());
        entretien.setIdCollaborateur(collaborateurController.getSelected());
        em.persist(entretien);
        for (int i = 0; i < 24; i++) {
            Integer maxIdNoteEntretien = (Integer) em.createQuery("SELECT MAX(n.idNoteEntretien) from 
   NoteEntretien n").getSingleResult();
            NoteEntretien noteEntretien = new NoteEntretien(maxIdNoteEntretien + 1);
            noteEntretien.setIdCollaborateur(collaborateurController.getSelected());
            noteEntretien.setIdCompetence(competences.get(i));
            noteEntretien.setIdEntretien(entretien);
            try {
                System.out.println(entretienController.getVal1());
                noteEntretien.setValNoteEntretien((float)entretienController.getVal1());
            } catch (Exception e) {
                e.printStackTrace();
            }
            
            em.persist(noteEntretien);
            listNoteEntretien.add(noteEntretien);
        }
    } catch (EJBException e) {
        @SuppressWarnings("ThrowableResultIgnored")
        Exception cause = e.getCausedByException();
        if (cause instanceof ConstraintViolationException) {
            @SuppressWarnings("ThrowableResultIgnored")
            ConstraintViolationException cve = (ConstraintViolationException) 
 e.getCausedByException();
            for (Iterator<ConstraintViolation<?>> it = cve.getConstraintViolations().iterator(); 
 it.hasNext();) {
                ConstraintViolation<? extends Object> v = it.next();
                System.err.println(v);
                System.err.println("==>>" + v.getMessage());
            }
        }
        System.err.println("ejb exception ! ! ! ! !");
    } finally {
        System.out.println("persistence OK !!!!!!!");
    }

}

The value retrieved is always set to 0 even if I select 1, 2, 3 or 4.

I tried a simple inputText and parse it to float on the defined method, then could get the proper value :

                                    <h3 style="width: 150px">Note</h3>
                                <p:inputText id="noteItem" value="#{entretienController.val1}">
                                    <p:ajax update="noteItem"/>
                                </p:inputText>

UPDATE :

I also tried a spinner and it works perfectly. The issue is just with the selectOneRadio

<p:outputLabel
                                    value="# 
 {bundle.Personnel_Aptitudes_Communication_Ecrite}"
                                    style="font-weight:bold"/>
                                <p:spinner id="noteItem" value="# 
 {entretienController.val1}">
                                    <p:ajax update="noteItem"></p:ajax>
                                </p:spinner>

Does anyone have the possibility to help me on that ?

Thank you !

0

There are 0 answers