1 2 Previous Next 25 Replies Latest reply on Feb 3, 2007 7:23 PM by pmuir

    selectItems exception

    damatrix

      Hello,

      I'm using Seam 1.1.0.GA, Ajax4JSF, Facelets and selectItems beta 1.1.1beta 4. This little bit of code on my page is giving me an exception immediately focus moves away from the selectOneMenu.

       <h:selectOneMenu id="pavilion" value="#{stand.pavilion}" required="true">
       <si:selectItems value="#{pavilionList}" var="pav" label="#{pav.title}" noSelectionLabel="-" />
       <a:support event="onblur" reRender="pavilionErrors"/>
       </h:selectOneMenu>
      


      The exception is below

      java.lang.NullPointerException
       at org.jboss.seam.selectitems.Config.find(Config.java:76)
       at org.jboss.seam.selectitems.Config$$FastClassByCGLIB$$13a6929b.invoke(<generated>)
       at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
       at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:45)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:55)
       at org.jboss.seam.interceptors.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:39)
       at sun.reflect.GeneratedMethodAccessor138.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
       at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
       at org.jboss.seam.interceptors.OutcomeInterceptor.interceptOutcome(OutcomeInterceptor.java:23)
       at sun.reflect.GeneratedMethodAccessor137.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
       at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
       at org.jboss.seam.interceptors.RollbackInterceptor.rollbackIfNecessary(RollbackInterceptor.java:33)
       at sun.reflect.GeneratedMethodAccessor140.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
      

      and a host of others. I'll give the whole stacktrace if required.

      My components.xml has this entry
      
       <core:managed-persistence-context name="em" persistence-unit-jndi-name="java:/tradeWindsEntityManagerFactory"/>
      
       <selectitems:config name="mySelectItemsConfig" no-selection-label="Please Select..." entity-manager="#{em}"/>
      


      and my persistence unit has the entry allowing seam to manage my persistence
      <property name="jboss.entity.manager.factory.jndi.name" value="java:/tradeWindsEntityManagerFactory"/>
      


      The entity manager is properly injected in my seam components using @In(create=true). Could it be something to do with A4JSF trying to validate the field? I get the feeling i'm doing something wrong but i've no idea what it is. I really need help cos i'm running out of time as this is my project work i have to submit very soon. Thanks anybody.

        • 1. Re: selectItems exception
          pmuir

          Does it work properly without A4J? - I've never tested it with A4J.

          N.B. The problem could well be that you have given a name to the si:config in components.xml - as a result you are configuring a seperate instance of the config rather than the default. Try it without the name.

          • 2. Re: selectItems exception
            damatrix

            I have tried taking out the A4J tags and removed the name from si:selectitems configuration but to no avail.

            I think the problem is from the seam managed persistence context. During startup seam loads it up as a component as shown below

            00:08:02,125 INFO [Component] Component: em, scope: CONVERSATION, type: JAVA_BEAN, class: org.jboss.seam.core.ManagedPersistenceContext
            
            


            The selectitems documentation stated that i needed to make sure that my enties were managed by a seam managed persistence context, and since i'd been using "em" to represent my entity manager, i just configured a seam managed persistence context with the same "em" name for my entity manager in my EJBs.

            However i still get the following exception when i try to inject it using the @In notation, unless i set create to true, i.e @In(create=true).

            javax.ejb.EJBTransactionRolledbackException: org.jboss.seam.RequiredException: In attribute requires value for component: pavilionListing.em
             at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:93)
             at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
             at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:83)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            



            Added to that, although the selectOneMenu DOES fill up with the list of objects i want selected, my save method is not called when i click it(it uses h:commandButton) i.e. nothing happens . When i change it to use s:button the method on the EJB does get called but i find that the outjected object that was to be populated with the data i specified is null.

            Do you think declaring a separate seam managed persistenc context to be used by select items will solve the problem and if so how do i do that?

            Hope that this level of detail is enough to help you determine what is wrong. Thanx for the effort.

            • 3. Re: selectItems exception
              pmuir

              You need to get a seam managed persistence context (i.e. inject the entity manager using @In) working first (from the above it sounds like it isn't). Follow the examples, search the forum, read the reference manual.

              • 4. Re: selectItems exception
                damatrix

                Hi,
                Thanks very much for the help. However i have managed all along in the development of my application to survive with the normal EJB style @PersistenceContext declaration on my entity manager instances in my bean. Does it mean that now that i need to make use of selectitems, i have to change all of them to use a seam managed persistence context, or can i just configure a seam managed persistence context and make that available to selectitems in my selectitems config? I pray u say the latter.

                • 5. Re: selectItems exception
                  pmuir

                  The latter probably will work. But you will have to use id equality on all the entities involved in selectitems

                  • 6. Re: selectItems exception
                    damatrix

                    Well, i reconfigured the managed persistence context as follows

                    <core:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/tradeWindsEntityManagerFactory"/>
                    
                    
                     <selectitems:config no-selection-label="-" entity-manager="#{entityManager}"/>
                    


                    The managed persistence context is properly injected now in the following bean

                    @Stateful
                    @Name("standManager")
                    public class StandObjectBean implements StandObjectLocal{
                    
                     @Out(required=false)
                     @In(required=false)
                     private StandDTO stand;
                    
                     @In
                     private EntityManager entityManager;
                    
                     @In
                     private FacesMessages facesMessages;
                    
                     @Out(required=false)
                     @In(required=false)
                     private PavilionDTO pavilion;
                    
                     public static String ADMIN_LIST = "marketing/admin/stands";
                    
                     /** Creates a new instance of StandObjectBean */
                     public StandObjectBean() {
                     }
                    
                     @Begin
                     public String createObject() {
                     stand = new StandDTO();
                     return NEW;
                     }
                    
                     @End
                     public String cancel() {
                     return ADMIN_LIST;
                     }
                    
                     @End
                     public String saveObject() {
                     new StandBO(entityManager).save(stand);
                     facesMessages.add("New stand added");
                     return ADMIN_LIST;
                     }
                    
                     @Destroy
                     @Remove
                     public void destroy() {
                     }
                    
                     @Factory("pavilionList")
                     public List<LocationDTO> createPavilionList(){
                     return new PavilionBO(entityManager).findAll();
                     }
                     @Factory("standTypeList")
                     public List<StandTypeDTO> createStandTypeList(){
                     return new StandTypeBO(entityManager).findAll();
                     }
                    
                    }
                    
                    


                    and my page is as ff:

                     <div class="label"><h:outputLabel for="pavilion" value="Pavilion "/></div>
                     <div class="input">
                     <h:selectOneMenu id="pavilion" value="#{stand.pavilion}" required="true">
                     <si:selectItems value="#{pavilionList}" var="pav" label="#{pav.title}"/>
                     </h:selectOneMenu>
                     <br/>
                     </div>
                    
                     <h:commandButton id="save" action="#{standManager.saveObject}" value="Save"/>
                    
                     <h:commandButton id="cancel" immediate="true" action="#{standManager.cancel}" value="Cancel"/>
                    


                    All my entities already use id equality, so i don't think that will be a problem. The most annoying part of this is that i don't get any exception so i can know what i'm doing wrong. the page just doesn't respond when i click the h:commandButton "Save", though as you can see bean has a saveObject method.

                    • 7. Re: selectItems exception
                      pmuir

                      make sure you have a h:messages component on the page.

                      • 8. Re: selectItems exception
                        damatrix

                        I do have an h:mesasges component on the page , but still get no faces messages and the page still doesn't respond.

                        don't you have any other suggestions i could try? i'm really at the end of my rope here. Feel like going back to the old jsf way of populating a SelectItems object and writing converter, but it's a task i don't relish.

                        • 9. Re: selectItems exception
                          pmuir

                          Unfortunately there are many places this could go wrong. I suggest putting a breakpoint in BasicEntityConverter.getAsObject() and see whether this method is even being called. Otherwise, it's the standard techniques of stripping out code until it works

                          It looks like it was at least getting called when you had ajax enabled so you shouldn't be far off. I suspect an exception is getting caught somewhere, hopefullya breakpoint will show you where.

                          Let me know how you get on.

                          • 10. Re: selectItems exception
                            damatrix

                            I went the route i dreaded by writing a converter the jsf way. It works alright cos i put a breakpoint in the converter to see if it was being called.

                            However as before my action on the h:commandButton is not being called as my page just flickers and comes back to me without an exception. As i described before it's only called when i change to an s:button, but my outjected object comes back with all the fields including the one from the selecOneMenu registering as null.

                            May i ask how different an h:commandButton is from an s:button apart from being able to pass method parameters in the latter?

                            That notwistanding, i want to try your suggestion. Excuse my ignorance but do i have to include the source code in my project to be able to debug it?

                            Thanxx very much for your patience.

                            • 11. Re: selectItems exception
                              pmuir

                              1) s:button/s:link don't submit the form, they just perform the action

                              2) Yes, you'll need to include the source to be able to set break points.

                              If you are still stuck, see if you can reproduce the problem in a new seam-gen project. If you can reproduce it, please send me a zip of the project with the lib directory removed (and let me know what version of Seam you used).

                              • 12. Re: selectItems exception
                                kukeltje

                                Read the documentation. The difference is described in there. Short summary:

                                s:button:
                                - does automatically propagate conversation
                                - does NOT post the fields to the jsf comonent

                                h:commandButton
                                - does NOT automatically propagate the conversation (use s:conversationpropagation for that)
                                - does post the fields to the jsf component.

                                I think this should go into the FAQ since it was one of the pitfalls I fell into as well (two times, even worse/stupid ;-))

                                • 13. Re: selectItems exception
                                  kukeltje

                                  me should look first, then comment:

                                  It alread IS in the problems FAQ:

                                  • 14. Re: selectItems exception
                                    pmuir

                                    Erm,

                                    "kukeltje" wrote:
                                    h:commandButton
                                    - does NOT automatically propagate the conversation (use s:conversationpropagation for that)


                                    Yes it does. s:conversationPropagtion is for *altering* the propagation (e.g. end, begin).

                                    The fom submission thing comes up time and time again!

                                    It does say this in the docs (I just added emphasis to the words 'this does not submit the form' :) )



                                    1 2 Previous Next