java - SelectItems of SelectOneMenu always null -
when test printing selected item in console , returned null
here method create selectitem in managedbean:
public list<string> getlistematricule() throws hibernateexception { list<string> matricules = new arraylist<string>(); (vehicule v : vehiculedao.getall()) { matricules.add(v.getmatricule()); system.out.println(v.getmatricule()); } return matricules ; } public list<selectitem> getallmatricules() { list<selectitem> options = new arraylist<selectitem>(); list<string> listmatricules = getlistematricule(); (string mat : listmatricules) { options.add(new selectitem(mat)); system.out.println("items = " + new selectitem(mat)); } return options ; }
and here variables in model contain getter , setters , constructor:
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 .... }
the methode bring variables database (list)
@override public vehicule getmatricule(string matricule) { session session = hibernateutil.currentsession(); vehicule v=(vehicule)session.get(vehicule.class, matricule); return v; }
and xhtml file, contains form:
<h:panelgrid columns="2" > <h:outputtext value="moniteur :" /> <h:selectonemenu id="listenomprenom" title="nom et prenom" value="{#programmb.np}"> <f:selectitems value="#{moniteurmb.allnomprenom}" /> </h:selectonemenu> <h:outputtext value="vehicule :" /> <h:selectonemenu id="listematricules" title="matricules" value="{#programmb.program.matricule}"> <f:selectitems value="#{vehiculemb.allmatricules}" /> </h:selectonemenu> <h:outputtext value="nombre heures:" /> <p:inputtext value="#{programmb.program.nbrheure}" /> </h:panelgrid> <p:commandbutton value="save" action="#{programmb.ajouterprog}" />
in first look, saw problem in value
attribute of both of selectonemenu bellow:
<h:selectonemenu id="listenomprenom" title="nom et prenom" value="{#programmb.np}"> <f:selectitems value="#{moniteurmb.allnomprenom}" /> </h:selectonemenu>
and:
<h:selectonemenu id="listematricules" title="matricules" value="{#programmb.program.matricule}"> <f:selectitems value="#{vehiculemb.allmatricules}" /> </h:selectonemenu>
in both of them putted #
in wrong place. change value="{#programmb.np}"
value="#{programmb.np}"
, value="{#programmb.program.matricule}"
value="#{programmb.program.matricule}"
, should work you!
Comments
Post a Comment