Note that there are some explanatory texts on larger screens.

plurals
  1. POSelectItems of SelectOneMenu always null
    primarykey
    data
    text
    <p>When I print the selected item in the console , it is always returned as null</p> <p>here is the method that create the SelectItem in my ManagedBean: </p> <pre><code>public List&lt;String&gt; getlisteMatricule() throws HibernateException { List&lt;String&gt; matricules = new ArrayList&lt;String&gt;(); for (Vehicule v : vehiculedao.getAll()) { matricules.add(v.getMatricule()); System.out.println(v.getMatricule()); } return matricules ; } public List&lt;SelectItem&gt; getAllMatricules() { List&lt;SelectItem&gt; options = new ArrayList&lt;SelectItem&gt;(); List&lt;String&gt; listMatricules = getlisteMatricule(); for (String mat : listMatricules) { options.add(new SelectItem(mat)); System.out.println("items = " + new SelectItem(mat)); } return options ; } </code></pre> <p>And here is my variables in my model which contain the getter and the setters and the constructor: </p> <pre><code>public class Program { private int id_progf; private int nbrHeure; private float montantGlobal; private String commentaire; private int cin_mon; private String matricule; private int cin_cand; ///gettersand setters .... } </code></pre> <p>The methode that bring the variables from the database (List) </p> <pre><code>@Override public Vehicule getMatricule(String matricule) { Session session = HibernateUtil.currentSession(); Vehicule v=(Vehicule)session.get(Vehicule.class, matricule); return v; } </code></pre> <p>And finally my xhtml file, it contains the form:</p> <pre><code>&lt;h:panelGrid columns="2" &gt; &lt;h:outputText value="Moniteur :" /&gt; &lt;h:selectOneMenu id="listeNomPrenom" title="Nom et Prenom" value="{#programMB.np}"&gt; &lt;f:selectItems value="#{moniteurMB.allNomPrenom}" /&gt; &lt;/h:selectOneMenu&gt; &lt;h:outputText value="Vehicule :" /&gt; &lt;h:selectOneMenu id="ListeMatricules" title="Matricules" value="{#programMB.program.matricule}"&gt; &lt;f:selectItems value="#{vehiculeMB.allMatricules}" /&gt; &lt;/h:selectOneMenu&gt; &lt;h:outputText value="Nombre heures:" /&gt; &lt;p:inputText value="#{programMB.program.nbrHeure}" /&gt; &lt;/h:panelGrid&gt; &lt;p:commandButton value="Save" action="#{programMB.ajouterProg}" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload