jsf 2 - How to get the objects in the targetList of a rich:pickList? -
i filled rightlist of picklist objects web service, when select elements, want these elements in mymanagedbean, because i'll affect them object.
jsf :
            <h:form>                 <rich:panel>                     <h:panelgrid columns="2" styleclass="criteressaisie"                         rowclasses="critereligne" columnclasses="titrecolonne,">                          <h:outputlabel for="libellecoplement" value="           "                             size="20" />                         <rich:picklist d="libellecoplement" sourcecaption="compléments"                             targetcaption="compléments sélectionnés"                             value="#{listecmpltdispomodel.listecmpltselect}" size="15"                             addtext=">" addalltext=">>" removetext="<"                             removealltext="<<" listwidth="270px" listheight="110px"                             orderable="true">                             <f:converter converterid="cmpltstitresconcerter" />                             <f:selectitems value="#{listecmpltdispomodel.listecmpltdispo}"                                 var="liste" itemlabel="#{liste.libellecomplement}"                                 itemvalue="#{liste.cdcomplement}"/>                          </rich:picklist>                     </h:panelgrid>                      <h:panelgroup>                         <div align="right">                             <h:panelgrid columns="8">                                 <h:commandbutton value="valider"                                     action="#{saisiecmpltstitrectrl.valider}" />                             </h:panelgrid>                         </div>                     </h:panelgroup>                  </rich:panel>             </h:form> the bean :
@managedbean(name = "listecmpltdispomodel") @sessionscoped public class listecmpltdispomodel implements serializable { private static final long serialversionuid = 1l;  private long cdcomplement; private string libellecomplement; private int nbcompl;  private list<complementsdisposortiedto> listecmpltdispo ; private list<complementsdisposortiedto> listecmpltselect ;  public listecmpltdispomodel() { }  public long getcodecomplement() {     return cdcomplement; }  public void setcodecomplement(long cdcomplement) {     this.cdcomplement = cdcomplement; }  public string getlibellecomplement1() {     return libellecomplement; }  public void setlibellecomplement1(string libellecoplement) {     this.libellecomplement = libellecoplement; }  public long getcdcomplement() {     return cdcomplement; }  public void setcdcomplement(long cdcomplement) {     this.cdcomplement = cdcomplement; }   public string getlibellecomplement() {     return libellecomplement; }  public void setlibellecomplement(string libellecomplement) {     this.libellecomplement = libellecomplement; }  public list<complementsdisposortiedto> getlistecmpltdispo() {     return listecmpltdispo; }  public void setlistecmpltdispo(list<complementsdisposortiedto> listecmpltdispo) {     this.listecmpltdispo = listecmpltdispo; }  public int getnbcompl() {     return nbcompl; }  public void setnbcompl(int nbcompl) {     this.nbcompl = nbcompl; }  public list<complementsdisposortiedto> getlistecmpltselect() {     return listecmpltselect; }  public void setlistecmpltselect(list<complementsdisposortiedto> listecmpltselect) {     this.listecmpltselect = listecmpltselect; } } converter :
@facesconverter(value="cmpltstitresconcerter") public class cmpltstitresconcerter implements converter {  @suppresswarnings("null") public object getasobject(facescontext context, uicomponent component,         string value){     complementsdisposortiedto cmpltselect = null;     cmpltselect.setcdcomplement(long.parselong(value));     return cmpltselect; }  public string getasstring(facescontext arg0, uicomponent arg1, object obj) {     return string.valueof(((complementsdisposortiedto) obj).getcdcomplement()); }  } any apprectiated!
roughtly need 3 things :
- custom converter object (object string, string object)
- getter/setter list of objects choices
- getter/setter list of objects selected
everything described here : richfaces showcase - picklist
edit :
adding should fix problem :
<rich:picklist ...>     <f:converter converterid="cmpltstitresconcerter" /> </rich:picklist> also converter property in <f:selectitems /> not valid : f:selectitems
edit :
you should modify converter remove converting exceptions :
@facesconverter(value="cmpltstitresconcerter") public class cmpltstitresconcerter implements converter {     public object getasobject(facescontext context, uicomponent component, string value)     {         complementsdisposortiedto cmpltselect = null;          if(value != null)         {             cmpltselect = new complementsdisposortiedto();             cmpltselect.setcdcomplement(long.parselong(value));         }          return cmpltselect;     }      public string getasstring(facescontext arg0, uicomponent arg1, object obj)     {         string result = null;          if(obj != null)         {             result = string.valueof(((complementsdisposortiedto) obj).getcdcomplement());         }          return result;     } } 
Comments
Post a Comment