8 Replies Latest reply on Jul 24, 2012 12:42 PM by Rui Albuquerque

    <rich:pickList>

    Rui Albuquerque Newbie

      Hi.

       

      So i have been trying to use a pickList to pass objects from a lsit to another. But when i acces the list of selected objects in a <rich:dataTable>, after the pickList, the selected items list is empty... I'm new to richfaces and web design in general so i assume i might have something wrong with the way i'm using the pickList. Could someone help me?

       

      Thanks in advance.

       

       

      Here's the portion of code that contains the pickList

       

       

       

        • 1. Re: <rich:pickList>
          Rui Albuquerque Newbie

          Aparently the code did not load into the message(i used the inser raw html. guess that's not what it was for), so here it goes again:

           

          <h:form>

               <rich:pickList value="#{UpperTrayBean.ASRselected}" sourceCaption="Available ASR Nodes" targetCaption="Selected ASR Nodes"

                                   listWidth="165px" listHeight="100px" orderable="true">

                    <f:selectItems value="#{UpperTrayBean.getASR()}" var="asr" itemValue="#{asr}" itemLabel="#{asr.getNodenumber()}" />

               </rich:pickList>

          </h:form>

          <h:form>

               <a4j:commandButton value = "Submit" action = "#{UpperTrayBean.setOn(true)}" style = "width:75px

               <a4j:commandButton value = "Refresh" action = "#{UpperTrayBean.setOn(true)}" reRender = "dataTable" style = "width:75px"/>

          </h:form>

          • 2. Re: <rich:pickList>
            Rui Albuquerque Newbie

            I added a converter after the <f:selectsitems> and removed the itemLabel proprety.

             

             

            Its still the same problem. but i think the proble is in the converter, because now, instead of the name of the ASR object, in the label, it apears its toString()representation...

             

            is there something wrong in the converter?

             

            @FacesConverter("ASRConverter")

            public class ASRConverter implements Converter {

             

                      @Override

                public String getAsString(FacesContext facesContext, UIComponent component, Object asr) {

                                if (asr == null) return "No Object";

                    return ((ASR) asr).getNodenumber();

                }

             

             

                      @Override

                      public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {

                                for( int n=0; n< UpperTrayBean.getasr().size(); n++){

                                          if (UpperTrayBean.getasr().get(n).getNodenumber().equals(arg2)){

                                                    return UpperTrayBean.getasr().get(n);

                                          }

                                }

                                return null;

                      }

             

             

            }

            • 3. Re: <rich:pickList>
              Ernesto Hernandez Newbie

              Hi Rui!

               

              I think you should have the commandButtons and the pickList inside de same form. Why don't you try that?

               

              Regards!

              • 4. Re: <rich:pickList>
                Rui Albuquerque Newbie

                Hi Ernesto.

                 

                Unfortunatly it didn't help.

                 

                But thanks for the reply!

                • 5. Re: <rich:pickList>
                  Ernesto Hernandez Newbie

                  Why did you remove the itemLabel? If you use the itemLabel, you must to set a property of the object (item) specified in the var property, not a getter method.

                  I think you should change your itemLabel to itemLabel="#{asr.nodenumber}".

                   

                  Check out my pickList:

                                          <h:form id="frm">

                                              <rich:pickList value="#{workListBean.selectedColumns}" sourceCaption="Columnas disponibles" targetCaption="Lista de Trabajo"

                                                      listWidth="165px" listHeight="100px" orderable="true" switchByDblClick="true"

                                                      style="text-align: left; color: #cc0033"

                                                      onremoveitems="alert('Hello');" id="pick"

                                                      ontargetclick="test(event);" >

                                                  <f:selectItems value="#{workListBean.availableColumns}" var="column" itemValue="#{column}" itemLabel="#{column.label}" />

                                                  <f:converter converterId="ColumnsConverter" />

                                              </rich:pickList>

                                              <br />

                                              <div align="right">

                                                  <h:commandButton value="Guardar" action="#{workListBean.saveCustomization}" />

                                              </div>

                                          </h:form>

                   

                  And my converter:

                   

                  @FacesConverter("ColumnsConverter")

                  public class ColumnsConverter implements Converter{

                   

                      @ManagedProperty(value="#{workListBean}")

                      private WorkListBean workListBean;

                     

                      public Object getAsObject(FacesContext facesContext, UIComponent component, String s) {

                          for (WorkList column: getColumnsList(facesContext)) {

                              if (column.getLabel().equals(s)) {

                                  return column;

                              }

                          }

                          return null;

                      }

                   

                      public String getAsString(FacesContext facesContext, UIComponent component, Object o) {

                          if (o == null) return null;

                          return ((WorkList) o).getLabel();

                      }

                   

                      private List<WorkList> getColumnsList(FacesContext facesContext) {       

                          return getWorkListBean(facesContext).getAvailableColumns();

                      }

                   

                      /**

                       * @return the workListBean

                       */

                      public WorkListBean getWorkListBean(FacesContext facesContext) {

                          if (workListBean == null) {

                              ELContext elContext = facesContext.getELContext();

                              workListBean = (WorkListBean) elContext.getELResolver().getValue(elContext, null, "workListBean");

                          }

                         

                          return workListBean;

                      }

                   

                      /**

                       * @param workListBean the workListBean to set

                       */

                      public void setWorkListBean(WorkListBean workListBean) {

                          this.workListBean = workListBean;

                      }

                        

                  }

                   

                  I hope this can help you!

                   

                  Regards!

                  • 6. Re: <rich:pickList>
                    Rui Albuquerque Newbie

                    Hi Ernesto.

                     

                    Your solution worked perfectly.

                     

                    The problem was that my converter didn't have a Facescontext part.

                     

                    Thank you!

                    • 7. Re: <rich:pickList>
                      Ernesto Hernandez Newbie

                      You're welcome! I'm glad you found the solution.

                       

                      Regards!

                      • 8. Re: <rich:pickList>
                        Rui Albuquerque Newbie

                        Hi Ernesto.

                         

                        So i now took it up a notch and now have a list inside the asr class inside the Bean class, so i was wondering how the converter would go(the getAsObject method)...

                         

                        I tried it like this:


                        public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {

                         

                             List<ASR> lista = getUpperTrayBean(arg0).getAsr();

                         

                                  for (ASR asr : lista){

                                         for(Cards card : asr.getCards()){
                                             if (card.getSlot().equals(arg2)) {          
                                                 return card;

                                             }

                                         }

                                   }

                                  return null;
                             }

                         

                        Does that make sense at all?