3 Replies Latest reply on Jun 14, 2013 3:00 AM by ktulu

    picklist update target list

    ktulu Newbie

      Hi all,

      I'm facing a problem updating the target side of the picklist (richefaces 4.3).

      Here is my code :




                          <h:selectOneMenu value="#{myCtrl.option}" >

                              <f:selectItems value="#{userBean.options}" />


                          <h:commandButton value="load" action="#{myCtrl.updateList}"/>


                                      <rich:pickList value="#{listBean.selection}"






                                          <f:selectItems value="#{listBean.toSelect}" />

                                          <f:converter converterId="itemConverter"  />


                                              <f:facet name="header">Column1</f:facet>




                                              <f:facet name="header">Column2</f:facet>




                          <h:commandButton value="OK" action="#{myCtrl.save}"/>




      public class ItemConverter implements Converter {



                private UserBean userBean;


                public MarkConverter() {

                          // TODO Auto-generated constructor stub





                public Object getAsObject(FacesContext fc, UIComponent arg1, String s) {


                               for (Item m : getUserBean().getItems()) {

                  if (m.getCol1().equals(s)) {

                      return m;



              return null;




                public String getAsString(FacesContext arg0, UIComponent arg1, Object o) {


                               if (o == null) return null;

              return ((Item) o).getCol1();




                public UserBean getUserBean() {

                               return userBean;




                public void setUserBean(UserBean userBean) {

                               this.userBean = userBean;








      public class ListBean {


                private List<Item> toSelect;

                private List<Item> selection;


                public List<Item> getToSelect() {

                               return toSelect;



                public void setToSelect(List<Item> toSelect) {

                               this.toSelect = toSelect;



                public List<Item> getSelection() {

                               return selection;



                public void setSelection(List<Item> selection) {

                               this.selection = selection;



                public ListBean() {








      public class MyController implements Serializable {


                private Logger log = Logger.getLogger(MyController.class);



                private UserBean userbean;



                private ListBean listBean;


                private String option;


                public String initItems() {


                               log.debug("initializing items");

                               if (listBean.getToSelect() == null || listBean.getToSelect().isEmpty()) {


                                              log.debug("initializing toselect");


                  List<Item> list = new ArrayList<Item>();





                               return "myPage";






                public String updateItems() {


                               List<Item> toselect = new ArrayList<Item>();

                               List<Item> selection = new ArrayList<Item>();


             // process to fill the lists //





             log.debug("list selection size=" + listBean.getSelection().size());

             log.debug("list toselect size=" + listBean.getToSelect().size());


             return "myPage";



                public MyController() {




                public String save() {

             log.debug("saving itemss");

                               for (Item i : listBean.getSelection()) {

                                              log.debug("item selected : " + m.getCol1());


                               return "myPage";




                public UserBean getUserbean() {

                               return userbean;




                public void setUserbean(UserBean userbean) {

                               this.userbean = userbean;



                public ListBean getListBean() {

                               return listBean;




                public void setDelegationList(ListBean listBean) {

                               this.listBean = listBean;



                public String getOption() {

                               return option;




                public void setOption(String option) {

                               this.option = option;





      the problem :

      When I click on the "OK" button, the save action is launch, I'm getting the selection and when I'm back on the page, the picklist is filled properly on the both side. But when I click on the "load" button, I'm properly setting the lists in the listBean (according to the logs) but when I'm back on the page, only the left side of the picklist is updated, the target list remains empty.

      I've tried a lot of workaround by I don't have any more idea...

        • 1. Re: picklist update target list
          Brian Leathem Master

          In your Item Object, do you have you overridden both equals and hashCode?  It's unfortunate that overriding hashCode is required, we plan to correct this in a future release.


          See this thread for details:


          • 2. Re: picklist update target list
            Siva P Master

            Do override the below methods in your entity class to avoid problems(same object) in moving data from lefe to right and vice versa,



                public boolean equals(Object obj) {

                    if (!((obj != null) && obj instanceof EntityObj)) {

                        return false;



                    EntityObj  rSubType = (EntityObj) obj;


                    if (this.getPrimarykeyId()!=null && this.getprimaryKeyId().equals(rSubType.getPrimarykeyId())) {

                        return true;



                    return false;




                public int hashCode() {

                    return (this.primarykeyId== null) ? 0 : primaryKeyId.hashCode();


            • 3. Re: picklist update target list
              ktulu Newbie

              Thanks for you reply.


              I've seen these equals and hashCode issues but the problem was somewhere else.


              I've finally fixed the problem which was the way I was initializing the lists.

              Under // process to fill the lists // in myCtrl,  I was filling the toSelect list with all the available items but the selected ones, which were placed in the selection list.

              I've changed it to keep all the available items in the toSelect list regardless what was in the selection list.


              Thanks again...