11 Replies Latest reply on Aug 6, 2008 2:32 AM by cibermon

    problem with listShuttle

    cibermon

      Hi.

      I have a listShuttle of objects of type "Denegacion" but it does not refresh the list of target elements. Something more has to be done apart from what exists in the example of use to achieve that it refills the list I target?

      <rich:listShuttle sourceValue="#{denegacionBean.denegacionesAnteriorCurso}"
      targetValue="#{denegacionBean.denegacionesMigracion}" var="items" sourceListWidth="200" targetListWidth="200" sourceCaptionLabel="Denegaciones Disponibles" targetCaptionLabel="Denegaciones a Migrar"
      converter="listShuttleDenegacionConverter">
      <rich:column>
      <h:outputLabel id="labelDenegacion" value="#{items.denegacion}">
      </h:outputLabel>
      </rich:column>
      </rich:listShuttle>
      <h:commandButton value="Migrar" action="#{denegacionBean.migrar}" />
      <h:commandButton value="Volver" action="MOTIVOSDENEGACION" immediate="true" />


      I am working with hibernate, and the list is a list of objects that I want to guard in BBDD, for it I call to the method To "migrar"


      where the failure?

        • 1. Re: problem with listShuttle
          ilya_shaikovsky

          place please rich:messages somewhere on the page.

          • 2. Re: problem with listShuttle
            cibermon

            When I select one element to copy from source list, It appear this message:

            migracion:listaShuttle: Validation Error: Value es.carm.bonolibro.modelo.Denegaciones@205144 is not valid

            I don't know the reason of the mistake. The Converter class is:

            public class DenegacionConverter implements javax.faces.convert.Converter{

            public Object getAsObject(FacesContext context, UIComponent component,
            String value) {

            int index;
            String denegacion;
            String cursoEscolar;

            index = value.indexOf(':');

            denegacion=value.substring(0, index);
            cursoEscolar=value.substring(index + 1);

            return new Denegaciones(denegacion, cursoEscolar);
            }

            public String getAsString(FacesContext context, UIComponent component,
            Object value) {

            Denegaciones denegacion = (Denegaciones) value;
            return denegacion.getDenegacion() + ":" + denegacion.getCursoEscolar();
            }

            }

            Can you help me?

            • 3. Re: problem with listShuttle
              ilya_shaikovsky

              check also that you carefuly override hashCode and equals methods inside your object as it shown on demo.

              • 4. Re: problem with listShuttle
                cibermon

                my hashcode and equals

                public boolean equals (Object obj) {
                if (null == obj) return false;
                if (!(obj instanceof es.carm.bonolibro.modelo.Denegaciones)) return false;
                else {
                es.carm.bonolibro.modelo.Denegaciones denegaciones = (es.carm.bonolibro.modelo.Denegaciones) obj;
                if (null == this.getId() || null == denegaciones.getId()) return false;
                else return (this.getId().equals(denegaciones.getId()));
                }
                }

                public int hashCode () {
                if (Integer.MIN_VALUE == this.hashCode) {
                if (null == this.getId()) return super.hashCode();
                else {
                String hashStr = this.getClass().getName() + ":" + this.getId().hashCode();
                this.hashCode = hashStr.hashCode();
                }
                }
                return this.hashCode;
                }

                • 5. Re: problem with listShuttle

                  Hello cibermon,

                  Do you have solved the problem? I have got the following error message of listShuttle.

                  has invalid value expression 28227,NDR FS SH"), detail=("Component j_id1235:j_id1238:j_id1239:playoutServiceListIdU has invalid value expression 28227,NDR FS SH")]
                  


                  The listShuttle is embedded in Modalpanel. The initialization both sites of listShuttle with sourcelist and targetlist. I try to remove the item from targetlist. The first operation is ok, but the subsequent remove i get the error message. I have the convert and the methods: equals, hashCode in java object.
                  the java code:
                  public class Service implements Serializable
                  {
                   /**
                   *
                   */
                   private static final long serialVersionUID = -5189169928936668620L;
                   private int id;
                   private String name;
                  
                   public Service(int id, String name)
                   {
                   super();
                   this.id = id;
                   this.name = name;
                   }
                  
                   public int getId()
                   {
                   return id;
                   }
                  
                   public void setId(int id)
                   {
                   this.id = id;
                   }
                  
                   public String getName()
                   {
                   return name;
                   }
                  
                   public void setName(String name)
                   {
                   this.name = name;
                   }
                  
                   public String toString()
                   {
                   return id + "," + name;
                   }
                  
                   public int hashCode() {
                   final int prime = 31;
                   int result = 1;
                   result = prime * result + ((name == null) ? 0 : name.hashCode());
                   result = prime * result + ((id == 0) ? 0 : String.valueOf(id).hashCode());
                   return result;
                   }
                  
                   public boolean equals(Object obj) {
                   if (this == obj)
                   return true;
                   if (obj == null)
                   return false;
                   if (getClass() != obj.getClass())
                   return false;
                   final Service other = (Service) obj;
                   if (name == null) {
                   if (other.name != null)
                   return false;
                   } else if (!name.equals(other.name))
                   return false;
                   if (id != other.id)
                   return false;
                   return true;
                   }
                  }
                  


                  the load method
                  
                   public List<Service> updatedServices(String inputFileName, List<Service> oldServices)
                   {
                   List<Service> temp = new ArrayList<Service>();
                   if(inputFileName !=null )
                   {
                   List<Service> availableServices = loadService(inputFileName);
                   if(availableServices != null)
                   {
                  
                   for(Service s: oldServices)
                   {
                   if(availableServices.contains(s))
                   {
                   temp.add(s);
                   availableServices.remove(s);
                  // oldServices.remove(s);
                   }
                   }
                   this.setAvailableServices(availableServices);
                   if(oldServices.size() == 0)
                   {
                   this.setCurrentServices(Collections.EMPTY_LIST);
                   }else
                   {
                   this.setCurrentServices(temp);
                   }
                   }else
                   {
                   this.setAvailableServices(Collections.EMPTY_LIST);
                   this.setCurrentServices(Collections.EMPTY_LIST);
                   }
                   }
                   return temp;
                   }
                  


                  • 6. Re: problem with listShuttle
                    cibermon

                    It's very important that the converter class save and load the objects in the same order, Por example:

                    ...

                    Class car{
                    private String A
                    private String B
                    }

                    ....

                    public void "save"{
                    return a + " " + b
                    }

                    public void "load"(String C){
                    a= C.substring(0, C.indexof(" "));
                    b = C.substring(C.indexof(" ")+1);
                    }

                    Do you understand me??

                    • 7. Re: problem with listShuttle

                      hi cibermon,

                      thank you very much. i will try with your advice.

                      • 8. Re: problem with listShuttle

                        hi cibermon,

                        how can i use those method in converter class?

                        code of java object:

                        public class Service implements Serializable
                        {
                         /**
                         *
                         */
                         private static final long serialVersionUID = -5189169928936668620L;
                         private int id;
                         private String name;
                        
                         public Service(int id, String name)
                         {
                         super();
                         this.id = id;
                         this.name = name;
                         }
                        
                         public int getId()
                         {
                         return id;
                         }
                        
                         public void setId(int id)
                         {
                         this.id = id;
                         }
                        
                         public String getName()
                         {
                         return name;
                         }
                        
                         public void setName(String name)
                         {
                         this.name = name;
                         }
                        
                         public String toString()
                         {
                         return id + "," + name;
                         }
                        
                         public int hashCode() {
                         final int prime = 31;
                         int result = 1;
                         result = prime * result + ((name == null) ? 0 : name.hashCode());
                         result = prime * result + ((id == 0) ? 0 : String.valueOf(id).hashCode());
                         return result;
                         }
                        
                         public boolean equals(Object obj) {
                         if (this == obj)
                         return true;
                         if (obj == null)
                         return false;
                         if (getClass() != obj.getClass())
                         return false;
                         final Service other = (Service) obj;
                         if (name == null) {
                         if (other.name != null)
                         return false;
                         } else if (!name.equals(other.name))
                         return false;
                         if (id != other.id)
                         return false;
                         return true;
                         }
                        }
                        


                        convert class
                        public class ServiceConverter implements Converter
                        {
                         public Object getAsObject(FacesContext arg0, UIComponent arg1, String value)
                         {
                         int index = value.indexOf(',');
                        
                         return new Service(Integer.valueOf(value.substring(0, index)),value.substring(index + 1));
                        
                         }
                        
                         public String getAsString(FacesContext arg0, UIComponent arg1, Object value)
                         {
                         Service optionItem = (Service) value;
                         return optionItem.getId() + "," + optionItem.getName() ;
                         }
                        
                        }
                        


                        • 9. Re: problem with listShuttle
                          cibermon

                          You must to have:

                          The Class Converter ok
                          The Bean o Basic Class ok

                          And now you must to have in your JSP or JSF something as:

                          <rich:listShuttle id="YYY" sourceValue="#{XXXBean.sourceList}"
                          targetValue="#{XXXBean.targetValue}"
                          var="items" sourceListWidth="200" targetListWidth="200" sourceCaptionLabel="Lo que sea (Something jejejeje)"
                          targetCaptionLabel="Lo que sea (Something)"
                          converter=Your Class Converter
                          listsHeight="150">

                          I explain it.

                          When your JSP load richfaces will invoke getAsString method of your Class Converter and if you select a element when JSP submit a request richfaces will invoke getAsObject for earch selected element.

                          I'm sorry for my English level.

                          Saludos :P

                          • 10. Re: problem with listShuttle

                            thank you very much for your clear explain. i have the converter class with overrided methods: getAsString() and getAsObject(). and the object in listShuttle is with equals() and hashcode() methods. I have two listShuttles. One is used as service filter. You can selecte many items(Services) from left sourceList to right targetList. By load, the left site with default items, and the right site is empty. The copy and remove works fine. But another listShuttle is used to update the service-filter. By load, the sourceList and targetList both with items. You can select new item from sourceList to targetList, and also remove items from targetList to sourceList.

                            <rich:listShuttle var="items" id="playoutServiceListIdU"
                             targetValue="#{updatedTaskDialogBean.playoutTaskBean.currentServices}"
                            
                             targetCaptionLabel="Current Service Filter"
                             sourceValue="#{updatedTaskDialogBean.playoutTaskBean.availableServices}"
                             sourceCaptionLabel="Avaible Services"
                             copyControlLabel="Add service"
                             converter="#{ServiceConverterForListShuttle}"
                             removeControlLabel="Remove service"
                             fastMoveControlsVisible="false"
                             fastOrderControlsVisible="false" columnClasses="taskColumns"
                             orderControlsVisible="false" listsHeight="150px"
                             style="width: 220px;"
                             valueChangeListener="#{updatedTaskDialogBean.playoutTaskBean.valueChangeListener}">
                             <a4j:support event="onlistchanged" ajaxSingle="true"/>
                             <rich:column width="15">
                             <f:facet name="header">
                             <h:outputText value="ID" />
                             </f:facet>
                             <h:outputText value="#{items.id}" />
                             </rich:column>
                            
                             <rich:column >
                             <f:facet name="header">
                             <h:outputText value="Name" />
                             </f:facet>
                             <h:outputText value="#{items.name}" />
                             </rich:column>
                             </rich:listShuttle>
                            

                            only with the a4j:support i can get the source/targetList. without the copy and remove has not effect. With a4j.support i can only remove the first item from targetList, the subsequent remove i get the error message: no valid expression.With debug i found, that the new item remove from targetList and put in sourceList, then call the getAsObject method. the originally items is ok, only there is the error message with the object removed from targetList.

                            I think, the problem is that, the sourceList can not identify the new item which come from targetList.

                            • 11. Re: problem with listShuttle
                              cibermon

                              valueChangeListener="#{updatedTaskDialogBean.playoutTaskBean.valueChangeListener}">
                              <a4j:support event="onlistchanged" ajaxSingle="true"/>

                              What you want to do with that Listener?? It's not necesary to manipulate list sufftles

                              You should to try with a easy example.