9 Replies Latest reply on Dec 29, 2011 1:46 AM by sanjeevim

    Richfaces listShuttle and Seam

    paulmkeogh

      I am using an EntityQuery to populate a Richfaces listShuttle control. I am also using the Seam EntityConverter. This all works well and I get execute a query, get back a List of my entites and they appear in the listShuttle source view. I can move them back and forward between the source and target views.


      However, no matter what I try I cannot submit the selected target entities back. I can see the method I associate with the Submit button being invoked but the target collection is always null.


      Do I need a custom converter ?


      Thanks,

        • 1. Re: Richfaces listShuttle and Seam

          I am using RF pickLists, which are very similar, with no problem.


          I'm not using a custom converter.


          Perhaps the issues lies in the entity bean rather than their action class?

          • 2. Re: Richfaces listShuttle and Seam
            swd847

            I have never managed to get s:convertEntity to work with the RF picklist or listshuttle. Also I think that the listshuttle was buggy in some versions of richfaces, as I had the exact same problems with it (can't remember the details, I basically just stopped using it). Try writing a custom converter, and if that still doesn't work upgrade to the latest RF version.

            • 3. Re: Richfaces listShuttle and Seam
              paulmkeogh

              I upgraded to RF 3.3.1 and got the same result. I will try replacing listShuttle with pickList to see if that component works.


              Can anyone point me at a working RF listShuttle example that uses s:convertEntity ???

              • 4. Re: Richfaces listShuttle and Seam
                gjeudy

                Hi Paul,


                I never got s:convertEntity to work with a listShuttle, don't remember the exact problem I was having... I had to write a custom converter.


                I'm using richfaces 3.2.1.GA.


                See trimmed down listShuttle code:


                <rich:listShuttle id="toRelShuttle"
                                                   targetValue="#{relatedToInstances}"
                                                   sourceValue="#{unrelatedToInstances}"
                                                   converter="#{my.custom.converter.IdentifiableConverter}"
                     
                                                   var="domInstVO">
                                                   <h:column>
                                                        <f:facet name="header">
                                                             <h:outputText value="Name" />
                                                        </f:facet>
                                                        <h:outputText
                                                             value="#{domInstVO.relationshipInstanceMember.description}" />
                                                   </h:column>
                                                   <h:column>
                                                        <f:facet name="header">
                                                             <h:outputText value="Code" />
                                                        </f:facet>
                                                        <h:outputText
                                                             value="#{domInstVO.relationshipInstanceMember.codeValue}" />
                                                   </h:column>
                                                        </rich:listShuttle>



                custom converter code:


                package my.custom.converter;
                
                import static org.jboss.seam.ScopeType.CONVERSATION;
                
                import java.io.Serializable;
                import java.util.HashMap;
                import java.util.Map;
                
                import javax.faces.component.UIComponent;
                import javax.faces.context.FacesContext;
                
                import org.jboss.seam.ScopeType;
                import org.jboss.seam.annotations.Name;
                import org.jboss.seam.annotations.Role;
                import org.jboss.seam.annotations.Scope;
                import org.jboss.seam.annotations.faces.Converter;
                import org.jboss.seam.annotations.intercept.BypassInterceptors;
                
                import a.b.c.entity.Identifiable;
                
                @Name("my.custom.converter.IdentifiableConverter")
                @Scope(CONVERSATION)
                @Converter
                @BypassInterceptors
                public class IdentifiableConverter implements  javax.faces.convert.Converter, Serializable {
                
                     private static final long serialVersionUID = 795578966690874286L;
                     
                     Map<String, Identifiable<Object>> map = new HashMap<String, Identifiable<Object>>();
                     
                     public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {     
                          if(arg2 == null) return null;
                          
                          Object obj = map.get(arg2);
                          return obj;
                     }
                
                     @SuppressWarnings("unchecked")
                     public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
                          if(arg2 == null) {
                               return null;
                          }
                          
                          if(!(arg2 instanceof Identifiable)) {
                               throw new IllegalArgumentException("Cannot convert:" + arg2 + " must be an instanceof Identifiable");
                          }
                          Identifiable<Object> identifiable = (Identifiable<Object>)arg2;
                          Object id = identifiable.getId();
                          /**
                           * defensive measure in case we use this converter inside the seam conversation but with different types
                           * and key values are overlapping between types.
                           */
                          String uniqueKeyAcrossTypes = identifiable.getClass().getSimpleName() + id;
                          map.put(uniqueKeyAcrossTypes, identifiable);
                          return uniqueKeyAcrossTypes;
                     }
                
                }
                



                That solution works fine for me. Let me know if that helps.


                Regards,
                -Guillaume

                • 5. Re: Richfaces listShuttle and Seam
                  paulmkeogh

                  Chris Simons wrote on Jun 24, 2009 22:56:


                  I am using RF pickLists, which are very similar, with no problem.

                  I'm not using a custom converter.

                  Perhaps the issues lies in the entity bean rather than their action class?


                  I replaced the listShuttle control with the pickList one in the view and everything works ! - I made no change to either the bean or action classes.


                  So, I'm guessing there is a bug with the entityConverter/listShuttle combination.


                  Is it worthwhile to submit a JIRA issue on this ? I am still a relative newcomer to Seam and am not 100% confident that I am driving the listShuttle correctly.

                  • 6. Re: Richfaces listShuttle and Seam

                    That's good that you got it to work; I would recommend two things:


                    1) Post this message in the JBoss/RichFaces forum with the same question/problem


                    2) Then, if still unresolved, then I would definitely submit a JIRA issue;


                    Just remember that RichFaces and Seam are related only in integration; there are two different teams working on each platform.

                    • 7. Re: Richfaces listShuttle and Seam
                      mdesignz

                      I specify:
                      converter="org.jboss.seam.ui.EntityConverter"
                      and it works for me.

                      • 8. Re: Richfaces listShuttle and Seam
                        keurvet

                        Yes ! Thanks a lot, for this post, listShuttle is more powerfull than the simplified picklist and so the picklist can not be seen as a replacement option.

                        • 9. Re: Richfaces listShuttle and Seam
                          sanjeevim

                          Dear Guillaume,


                          I have work on with your code in jsf list shuttle, In the bean class there is error showing in particular package(i,e.import a.b.c.entity.Identifiable;
                          )The import a cannot be resolved.Can u send me the package for this.
                          or give the alternative solution..


                          Thanks in Advance,


                          Sanjeevi M