1 2 Previous Next 20 Replies Latest reply on Feb 6, 2007 5:27 AM by Fredric

    SeamSelectItems - 1.1.1beta4

    Pete Muir Master

      http://wiki.jboss.org/wiki/attach?page=SeamSelectItemsNewDesign%2Fselectitems-1.1.1beta4.zip

      I've updated this package, for now marked as a draft release (there are quite a few changes to the core code and I would like to get feedback).

      To upgrade

      As long as you are using a SMPC called entityManager (i.e. you do @In(create=true) EntityManager entityManager; normally), you can just update the jars and delete

      <component class="org.jboss.seam.selectitems.SelectItemsConfig">
       <property name="persistenceUnitJndiName">...</property>
      </component>


      from components.xml.

      If you use a different SMPC (e.g. called em - @In(create=true) EntityManager em;) then you'll need to let SeamSelectItems know about it:

      <component name="org.jboss.seam.selectitems.selectItemsConfig">
       <property name="entityManager">#{em}</property>
      </component>


      (n.b. the change from component class= to component name=)

      Post any problems here.

      The docs have also been updated http://www.jboss.com/wiki/Edit.jsp?page=SeamSelectItemsNewDesign

      Changes
      * BUG Remove need for id equality
      * BUG Remove need to configure persistenceUnitJndiName
      - The EntityConverter now uses the same SMPC as is used in the rest of the applicaiton.
      - If the SMPC is called entityManager (as generated by seam-gen) no configuration is needed, otherwise it must be configured in components.xml
      - Can no longer set persistenceUnitJndiName on si:convertEntity
      * Remove @SelectItems annotation
      * FEATURE Can now outject an array or DataModel (using @DataModel) as the list of selectitems
      * BUG Automatically instatiate SelectItemsConfig
      * BUG Don't error if @Entity is missing, on entity class, but, if cannot find @Id notify the user that @Entity is missing (due to Seam proxying)
      * BUG Fix ResourceNotFoundException thrown if an error is to be displayed

        • 1. Re: SeamSelectItems - 1.1.1beta4
          Ciro Cavani Novice

          Thanks, I am using this tag a lot.

          But, now, I could not figured out how set different SMPC for specific selectItem.

          In the same app, I have tree SMPC.... sometimes I use more than one on same long conversation...

          how can I set this?

          • 2. Re: SeamSelectItems - 1.1.1beta4
            Pete Muir Master

            Hehe.

            I removed the ability to specify a different PC on a per-selectitem-tag instance as I was quite convinced that no one would be using it.

            I'll probably do this as:

            components.xml

            <selectitems name="anotherConfig" entityManager="#{anotherEm}" />


            jsf
            <si:selectitems ... config="#{anotherConfig}" />


            • 3. Re: SeamSelectItems - 1.1.1beta4
              Ciro Cavani Novice

              nice to me.... for now, I must continue with previous version...

              Thanks,

              • 4. Re: SeamSelectItems - 1.1.1beta4
                Pete Muir Master

                Done as described above. Also, I added in a schema for components.xml.

                <selectitems:config name="anotherConfig" entity-manager="#{anotherEm}" />


                Also, the changes made in 1.1.1-beta4 broke the caching, so even you have cache=true, it won't actually cache anything.

                • 5. Re: SeamSelectItems - 1.1.1beta4
                  Pete Muir Master

                  In the latest draft selectMany's should 'just work' (without needing to specify the entityClass and converter). The way SeamSelectItems determines the class in this case is quite fragile, so (especially if you aren't using generics) you may still need to specify the converter and entityClass.

                  • 6. Re: SeamSelectItems - 1.1.1beta4
                    Mike Dougherty Newbie

                    Can this tag be used with non-Entity JavaBeans? I've tried just about every option discussed in the docs, but nothing seems to be working.

                    • 7. Re: SeamSelectItems - 1.1.1beta4
                      Pete Muir Master

                      Yes, the tag can be used, but you need to provide your own converter (based on SelectItemsConverter) or use the key="" attribute. Post the code you are currently trying.

                      • 8. Re: SeamSelectItems - 1.1.1beta4
                        Mike Dougherty Newbie

                        in home.xhtml:

                         <h:form id="selectSubject">
                         <h:selectOneMenu value="#{subject}">
                         <si:selectItems value="#{subjects}" var="s" label="#{s.title}" key="#{s.id}" ></si:selectItems>
                         </h:selectOneMenu>
                         </h:form>
                        


                        in Subject.java:
                        
                        @Name("subject")
                        public class Subject implements java.io.Serializable {
                         private static final long serialVersionUID = -1926918108184076192L;
                         private String id = "";
                         private String title = "";
                         private String description = "";
                        }
                        

                        It also contains getters and setters, but for brevity I left them out.

                        In SubjectFactoryBean.java
                        @Stateless
                        @Name("subjectFactory")
                        @Scope(APPLICATION)
                        public class SubjectFactoryBean implements SubjectFactory {
                        
                         @Logger
                         private Log log;
                        
                         @Out
                         private List<Subject> subjects;
                        
                         @Factory("subjects")
                         public void load() {
                         log.debug("Loading subject list.");
                        
                         subjects = new ArrayList<Subject>();
                         subjects.add( new Subject("sub-a", "Subject A") );
                         subjects.add( new Subject("sub-b", "Subject B") );
                         subjects.add( new Subject("sub-c", "Subject C") );
                        
                         log.debug("Subject list contains #0 entries.", subjects.size() );
                         }
                        }
                        


                        I'm getting the following error:

                        Value is no String (class=mil.fits.survey.Subject$$EnhancerByCGLIB$$5cdc06c9, value=subject = ) and component selectSubject:_id12with path: {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /home.xhtml][Class: javax.faces.component.html.HtmlForm,Id: selectSubject][Class: javax.faces.component.html.HtmlSelectOneMenu,Id: _id12]} does not have a Converter
                        


                        So I try adding a converter....

                        Adding this method to SubjectFactoryBean.java
                         public Converter getConverter() {
                         return new SelectItemsConverter() {
                         @Override
                         protected Object convertToObject(FacesContext arg0, UIComponent arg1, String arg2)
                         throws ConverterException {
                         log.debug("convertToObject(#0, #1, #2)", arg0, arg1, arg2);
                         // TODO Auto-generated method stub
                         return new Subject(arg2, arg2);
                         }
                        
                         @Override
                         protected String convertToString(FacesContext arg0, UIComponent arg1, Object arg2)
                         throws ConverterException {
                         log.debug("convertToString(#0, #1, #2)", arg0, arg1, arg2);
                         // TODO Auto-generated method stub
                         return arg2.toString();
                         }
                        
                         };
                         }
                        


                        And in home.xhtml...
                         <h:form id="selectSubject">
                         <h:selectOneMenu value="#{subject}" converter="#{subjectFactory.converter}">
                         <si:selectItems value="#{subjects}" var="s" label="#{s.title}" key="#{s.id}" ></si:selectItems>
                         </h:selectOneMenu>
                         </h:form>
                        
                        


                        Gives me the following error...
                        /home.xhtml @16,83 converter="#{subjectFactory.converter}": Exception
                        getting value of property converter of base of type :
                        org.jboss.seam.intercept.Proxy$$EnhancerByCGLIB$$4461012a
                        




                        • 9. Re: SeamSelectItems - 1.1.1beta4
                          Pete Muir Master

                          I can spot two problems

                          1) If you specify a key, then you should be the value attribute of the selectOneMenu should point to a String setter method (in this or the action method convert it to an object).

                          So this explains the first exception.

                          2) If you specify a converter then don't specify a key (that will just confuse things)

                          Quite why you got the second exception, I'm not sure, but I would suspect a classloading exception - make sure the selectitems.jar is in the classpath of the ear, and the selectitems-ui.jar is in the classpath of the war.

                          Btw I would recommend writing a custom converter to using a key.

                          • 10. Re: SeamSelectItems - 1.1.1beta4
                            Mike Dougherty Newbie

                            Thanks petemuir, using a String for the value worked. Not sure why I didn't see that based on the stack.

                            Also, I actually copied and pasted my code wrong. I didn't have the 'key' attribute at the same time as I had the converter configured. When I did it was a completely different exception.

                            Why would you recommend a custom converter over using a key? I still can't seem to get the converter to work. Seems no matter where I put the jar file I get NoClassDefFound exceptions. I'll have to keep digging into this. But before I spend a lot of time trying to figure it out, it would be nice to know why it would be a better approach.

                            BTW, the docs specify that both jars go in the WEB-INF/lib dir. You may want to update this if it is not the case.

                            Thanks again for the help.

                            • 11. Re: SeamSelectItems - 1.1.1beta4
                              Pete Muir Master

                              Why a converter? I simply think its a 'neater' approach - it makes the JSF cleaner (no logic about how the id's of your entities) AND you get an object back in your backing bean not a String so again, it makes the business logic cleaner (no presentation logic) BUT they are more effort to write.

                              You can take a look at the example - this uses an alternative converter in the backing bean. Alternatively you can do it the-jsf-way, and register a converter in faces-config and reference that.

                              The 'Getting Started' section of the docs say to put both in jars in WEB-INF/lib but the 'Reference Guide'/'Jars' discusses putting the selectitems.jar in the ear - I've updated the text to make it a bit clearer.

                              • 12. Re: SeamSelectItems - 1.1.1beta4
                                Mike Dougherty Newbie

                                Yeah, OK. That makes sense, and I do agree, it is more elegant. I thought maybe there was a performance or functional reason why you were recommending it.

                                I missed the JAR file description in the document, sorry about that.

                                I'm still having a bit of trouble with this converter.

                                public class SubjectSelectConverter extends org.jboss.seam.selectitems.jsf.SelectItemsConverter {
                                
                                 @Override
                                 protected Object convertToObject(FacesContext arg0, UIComponent arg1, String arg2)
                                 throws ConverterException {
                                 log.debug("convertToObject(#0, #1, #2)", arg0, arg1, arg2);
                                 return new Subject(arg2, arg2);
                                 }
                                
                                 @Override
                                 protected String convertToString(FacesContext arg0, UIComponent arg1, Object arg2)
                                 throws ConverterException {
                                 log.debug("convertToString(#0, #1, #2)", arg0, arg1, arg2);
                                 return arg2.toString();
                                 }
                                }
                                


                                Gives me:
                                Converter must implement SelectItemsConverter: mil.fits.survey.SubjectFactoryBean$SubjectSelectConverter@102c93e
                                


                                I even tried putting the selectitems-ui.jar in the EAR path to make sure the classloader could see the SelectItemsConverter when it instantiated SubjectSelectConverter. But no such luck. Doesn't make a lot of sense to me.


                                On a similar subject, I saw someplace that I could define a converter for a specific class globally. According to your post I guess that would be in faces-config.xml. But I didn't bookmark that page, and now cannot seem to find it again. It's sort of off topic, but do you know how I can associate a Converter with a JavaBean globally? It looked something like below, but I can't be absolutely sure.

                                 <converter>
                                 <bean-class>com.foo.app.Subject</bean-class>
                                 <converter-class>com.foo.app.SubjectConverter</converter-class>
                                 </converter>
                                


                                Thanks again for your help.

                                • 13. Re: SeamSelectItems - 1.1.1beta4
                                  Pete Muir Master

                                  The first issue I suspect is a class loading problem - you probably have multiple (stale) copies of the selectitems.jar floating around.

                                  SelectItemsConverter is IIRC in selectitems.jar not in selectitems-ui.jar for precisely this reason - so you can extend it in a backing bean. N.B. if you register the converter in faces-config.xml you can just package it in the war and then both selectitems jars can go in WEB-INF/lib

                                  http://java.sun.com/javaee/5/docs/tutorial/doc/index.html

                                  Step 4 of http://www-128.ibm.com/developerworks/library/j-jsf3/#N102AC

                                  • 14. Re: SeamSelectItems - 1.1.1beta4
                                    Fredric Newbie

                                    May I add aquestion in this discussion?

                                    I am trying to get S.S.I. to work with a stateless backingbean.
                                    The code below renders just fine, and my current value is set correctly as well. My problem arise when I submit the form with the selectOneMenu.
                                    I get the follwing exception:

                                    09:31:46,386 ERROR [PhaseListenerManager] Exception in PhaseListener RESTORE_VIEW(1) afterPhase
                                    .
                                    .
                                    .
                                    09:31:46,402 ERROR [SeamExceptionFilter] uncaught exception handled by Seam
                                    javax.servlet.ServletException: Could not restore StateHolder of type com.omxgroup.lap.acl.actions.ACLListActionImpl$1 (missing no-args constructor?)


                                    I've set up the following:

                                    Except of my backing bean
                                    @Stateless
                                    @Name("aclList")
                                    public class ACLListActionImpl implements ACLListAction {
                                    
                                    @SelectItems(labelMethod="getName", valueStrategy=SelectItems.Strategy.INDEX)
                                    private List rights;
                                    
                                    @Factory("rights")
                                    public List getRights() {
                                    
                                     if(rights == null){
                                     rights = em.createQuery("from ARO").getResultList();
                                    
                                     selAro = (ARO)rights.get(0);
                                     }
                                     return rights;
                                    }
                                    
                                    @Factory("converter")
                                     public Converter getConverter() {
                                     return new SelectItemsConverter() { ...
                                    



                                    Excerpt of my XHTML page
                                    <h:selectOneMenu id="selAro" value="#{selAcl.aro.name}" converter="#{converter}">
                                     <si:selectItems value="#{aclList.rights}" var="right" label="#{right.name}"/>
                                    </h:selectOneMenu>
                                    


                                    Hopefully I've got most of this right :-)

                                    As it is now, I can't save the changes I do in the form because of the exception.
                                    Have you guys some hints how I can correct this?

                                    1 2 Previous Next