4 Replies Latest reply on Feb 4, 2013 5:18 AM by sivaprasad9394

    set destination  rich:picklist

    raj_15.

      In rich:picklist i want to set the destination picklist which is coming from backing bean and i'm using jsf  2.0

      Thanks In Advance.

        • 1. Re: set destination  rich:picklist
          iabughosh

          welcome to the community Amande,

          try this :

           

          <rich:picklist value="#{myBean.selectedValues}">

               <f:selectItems value="#{myBean.sourceValues}" var="item" itemValue="#{item}" itemLabel="#{item}"/>

          </rich:picklist>

           

          where selectedValues is List<String> has these values {"Item 1","Item 2"}

          and sourceValues is List<String> has there values {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5"}

           

          Good Luck.

          • 2. Re: set destination  rich:picklist
            raj_15.

              <f:selectItems value="#{myBean.sourceValues}" var="item" itemValue="#{item}" itemLabel="#{item}"/>

             

            solution provided above is working fine but its change my  source list because of this source list printing employee object  instead of  employee name  .

            source list is

             

              <f:selectItems value="#{myBean.sourceValues}" var="item" itemValue="#{item.id}" itemLabel="#{item.name}"/>

            • 3. Re: set destination  rich:picklist
              sivaprasad9394

              Hi Amande,

               

              If you are using richfaces with seam means you can try with the below code....Home is nothing but BEAN class for your reference.

              XHTML page:

              <a4j:region renderRegionOnly="true">

              <rich:pickList id="userinfo"


              copyAllControlLabel="#{messages['button.SelectAll']}"

              copyControlLabel="#{messages['button.Select']}"

              removeControlLabel="#{messages['button.Remove']}"

              removeAllControlLabel="#{messages['button.RemoveAll']}"

              moveControlsVerticalAlign="middle" listsHeight="400px"

              style="marigin-left:-2px;" sourceListWidth="250px"

              targetListWidth="250px"       

              value="#{emptrainingrolemappingHome.resultRoles}">

              <s:selectItems value="#{emptrainingrolemappingHome.trainingRolesSelectItemList}" var="role"


              label="#{role.trainrolename}"/>


              <s:convertEntity></s:convertEntity>
               
              </rich:pickList></a4j:region>

              </rich:panel>

               

              <h:panelGrid id="panelgrdID" width="100%">

              <rich:toolBar id="toolbarButton" width="100%"


              styleClass="toolbar_up"

              rendered="#{emptrainingrolemappingHome.associateSelected}">



              <a4j:commandButton  id="savebtnID"

              rendered="#{emptrainingrolemappingHome.associateSelected}"



              action="#{emptrainingrolemappingHome.persistRoles()}"



              value="#{messages['button.Update']}"/>

              </rich:toolBar>

              </h:panelGrid>

               

              In the Bean class create like below,

               

              private List<Entity class or POJO class> resultRoles = new ArrayList<Entity class or POJO class>();

              List<Entity class or POJO class> trainingRolesSelectItemList = new ArrayList<Entity class or POJO class>();

               

               

                  public List<Entity class or POJO class> getTrainingRolesSelectItemList() {       

                      return trainingRolesSelectItemList;

                  }

               

               

                  public void setTrainingRolesSelectItemList(

                          List<Entity class or POJO class> trainingRolesSelectItemList) {       

                      this.trainingRolesSelectItemList = trainingRolesSelectItemList;

                  }

               

                public List<Entity class or POJO class> getResultRoles() {

                      return resultRoles;

                  }

               

                  public void setResultRoles(List<Entity class or POJO class> resultRoles) {

                      this.resultRoles = resultRoles;

                  }

               

              To save the data in the database after moving it to right side pick list:

               

              public String persistRoles() {

                    

                      if (resultRoles.size() == 0) { ///throws error for selecting one to right side

                          facesMessages.addFromResourceBundle(Severity.ERROR,

                              "#{messages['Administration.AssociateRoleMapping.togHeader']}");

                      } else {

                          //get existing mapped Roles

                          List<Entity class or POJO class> alreadyAssignedRoles = getAvailRoles();

               

                         //here suppose if alrady existing datas should be deleted from DB  and add the new list into it always .That is ood programming

               

                          for (int j = 0; j < alreadyAssignedRoles.size(); j++) {

                              Entity class or POJO class  etrm = (Entity class or POJO class) alreadyAssignedRoles.get(j);

                              deleteEmptrainingRoleMapping(etrm);

                          }

                          entityManager.flush();    

                        

                      // Iterate the resultRoles and insert into the DB here //****************** do your code*****************

               

                          facesMessages.addFromResourceBundle(Severity.INFO,

                              "#{messages['AssignAdmin.sucess_msg']}");

                      }

               

                      return "persisted";

                  }

                         

              I hope i have give correct way to picklist for storing into DB........

              Thanks,

              Siva

              • 4. Re: set destination  rich:picklist
                sivaprasad9394