6 Replies Latest reply on Jul 23, 2008 6:54 PM by theseamnewbie

    Checkboxes should be easy right?

    theseamnewbie

      Ok, I'm a total n00b so please forgive me for the following post.



      I have an object called Course. In this Course object is a Collection of CourseCurriculum objects.


      When on my page to add a new course (or edit for that matter) I would like to have checkoxes so the user can check which curriculums the course belongs too. The values that get checked should be stored in the Collection of CourseCurriculum objects within the new Course object.


      The list of curriculums needs to come from the database, so I am using h:selectManyCheckbox which (in theory) is populated with a list of curriculums.


      The problem that I'm running into is that I can't even render the page without the following error:


      Exception while calling encodeEnd on component : {Component-Path : [Class: org.ajax4jsf.component.AjaxViewRoot,ViewId: /ddlTest.xhtml][Class: javax.faces.component.html.HtmlForm,Id: j_id0][Class: javax.faces.component.html.HtmlSelectManyCheckbox,Id: j_id1]}
      
      Caused by:
      cause



      I've tried everything I can think of, but I'm stuck.  Right now I have just a simple web page that should display a bunch of checkboxes of courses.


      Below is what code I have so far:



      Entity:


      Course.java
      
      <...>
      
      @Entity
      @Name("course")
      public class Course implements Serializable{
      
      private long courseID;
      private String courseFullName;
      private Collection<CourseCurriculum> cCurriculum;
      



      Bean:


      CourseListAction.java
      
      <...>
      
      @Stateful
      @Name("CourseListSeam")
      public class CourseListAction implements CourseList, Serializable {
      
      @In(required=false) 
      @Out(required=false, scope = ScopeType.SESSION)
      @DataModelSelection
      protected Course course;
      
      @DataModel
      private Collection<Course> courses;
      
      @PersistenceContext(unitName = "ELCPU")
      private EntityManager entityManager; 
      
      
      @Factory
      @Observer("courseConfirmed")
      public Collection<Course> getCourses(){
      
      //get list of all courses
      courses = entityManager.createQuery("SELECT crs FROM Course crs ORDER BY crs.courseID").getResultList();
      
      //return list
      return courses;
      }
      
      



      HTML:


      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "" title="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">" class="link">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns = "http://www.w3.org/1999/xhtml"
      xmlns:ui = "http://java.sun.com/jsf/facelets"
      xmlns:h = "http://java.sun.com/jsf/html"
      xmlns:f = "http://java.sun.com/jsf/core"
      xmlns:s = "http://jboss.com/products/seam/taglib"
      xmlns:a4j = "http://richfaces.org/a4j"
      xmlns:rich = "http://richfaces.org/rich">
      
      <body>
      <ui:composition>
      <h:form>
      
      <h:selectManyCheckbox value="#{CourseListSeam.courses}">
      <s:selectItems value="#{CourseListSeam.getCourses}" var="crs" label="#{crs.courseID}"/>
      </h:selectManyCheckbox>
      
      </h:form> 
      </ui:composition>
      </body>
      </html> 




      Please help :(


        • 1. Re: Checkboxes should be easy right?
          ericjava.eric.chiralsoftware.net

          One very obvious problem I see:


          <s:selectItems value="#{CourseListSeam.getCourses}" var="crs" label="#{crs.courseID}"/>



          It should be:


          <s:selectItems value="#{CourseListSeam.courses}" var="crs" label="#{crs.courseID}"/>



          because it's using a property name.  There may be other problems, but that one stands out immediately.


          I think you also need s:convertEntity in there.


          -------------


          JBoss Seam seminars

          • 2. Re: Checkboxes should be easy right?
            theseamnewbie

            I think at one point I had it like that... I've tried so many different things though it's hard to remember.


            So now my file looks like this:



            <h:selectManyCheckbox value="#{CourseListSeam.courses}">
                
                <s:selectItems value="#{CourseListSeam.courses}" var="crs" label="#{crs.courseID}"/>
                <s:convertEntity />
             
            </h:selectManyCheckbox>



            I still have the same problem :(


            Could it have anything to do with the fact that I'm using Geronimo?


            Here's the stack trace:


            Exception while calling encodeEnd on component : {Component-Path : [Class: org.ajax4jsf.component.AjaxViewRoot,ViewId: /ddlTest.xhtml][Class: javax.faces.component.html.HtmlForm,Id: j_id0][Class: javax.faces.component.html.HtmlSelectManyCheckbox,Id: j_id1]}
            
            Caused by:
            cause
             
             
            - Stack Trace
            javax.faces.FacesException: Exception while calling encodeEnd on component : {Component-Path : [Class: org.ajax4jsf.component.AjaxViewRoot,ViewId: /ddlTest.xhtml][Class: javax.faces.component.html.HtmlForm,Id: j_id0][Class: javax.faces.component.html.HtmlSelectManyCheckbox,Id: j_id1]}
                 at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:559)
                 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:250)
                 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:246)
                 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:246)
                 at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
                 at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
                 at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
                 at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
                 at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:140)
                 at javax.faces.webapp.FacesServlet.service(FacesServlet.java:152)
                 at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
                 at org.apache.geronimo.jetty6.InternalJettyServletHolder.handle(InternalJettyServletHolder.java:65)
                 at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                 at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                 at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                 at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                 at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                 at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
                 at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
                 at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                 at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                 at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                 at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
                 at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
                 at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
                 at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
                 at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
                 at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
                 at org.apache.geronimo.jetty6.handler.TwistyWebAppContext.access$101(TwistyWebAppContext.java:40)
                 at org.apache.geronimo.jetty6.handler.TwistyWebAppContext$TwistyHandler.handle(TwistyWebAppContext.java:65)
                 at org.apache.geronimo.jetty6.handler.ThreadClassloaderHandler.handle(ThreadClassloaderHandler.java:46)
                 at org.apache.geronimo.jetty6.handler.InstanceContextHandler.handle(InstanceContextHandler.java:58)
                 at org.apache.geronimo.jetty6.handler.UserTransactionHandler.handle(UserTransactionHandler.java:48)
                 at org.apache.geronimo.jetty6.handler.ComponentContextHandler.handle(ComponentContextHandler.java:47)
                 at org.apache.geronimo.jetty6.handler.TwistyWebAppContext.handle(TwistyWebAppContext.java:59)
                 at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
                 at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
                 at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
                 at org.mortbay.jetty.Server.handle(Server.java:324)
                 at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
                 at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:828)
                 at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
                 at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
                 at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
                 at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
                 at org.apache.geronimo.pool.ThreadPool$1.run(ThreadPool.java:214)
                 at org.apache.geronimo.pool.ThreadPool$ContextClassLoaderRunnable.run(ThreadPool.java:344)
                 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
                 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
                 at java.lang.Thread.run(Thread.java:595)
            Caused by: java.lang.NullPointerException
                 at org.jboss.seam.ui.converter.entityConverter.EntityLoader.getPersistenceContext(EntityLoader.java:30)
                 at org.jboss.seam.ui.converter.entityConverter.EntityLoader.validate(EntityLoader.java:52)
                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                 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:21)
                 at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                 at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                 at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:38)
                 at org.jboss.seam.util.Work.workInTransaction(Work.java:40)
                 at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:32)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                 at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                 at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                 at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
                 at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
                 at org.jboss.seam.ui.converter.entityConverter.EntityLoader_$$_javassist_2.validate(EntityLoader_$$_javassist_2.java)
                 at org.jboss.seam.ui.converter.EntityConverter.init(EntityConverter.java:62)
                 at org.jboss.seam.ui.converter.EntityConverter.getAsString(EntityConverter.java:69)
                 at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getConvertedStringValue(RendererUtils.java:621)
                 at org.apache.myfaces.shared_impl.renderkit.RendererUtils.internalSubmittedOrSelectedValuesAsSet(RendererUtils.java:681)
                 at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getSelectedValuesAsSet(RendererUtils.java:596)
                 at org.apache.myfaces.shared_impl.renderkit.html.HtmlCheckboxRendererBase.renderCheckboxList(HtmlCheckboxRendererBase.java:112)
                 at org.apache.myfaces.shared_impl.renderkit.html.HtmlCheckboxRendererBase.encodeEnd(HtmlCheckboxRendererBase.java:65)
                 at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:556)
                 ... 56 more
            
            - Component Tree<AjaxViewRoot id="_viewRoot" immediate="false" locale="en" renderKitId="HTML_BASIC" renderRegionOnly="false" rendered="true" selfRendered="false" submitted="false" transient="false" viewId="/ddlTest.xhtml"><HtmlForm enctype="application/x-www-form-urlencoded" id="j_id0" prependId="true" rendered="true" submitted="false" transient="false"><HtmlSelectManyCheckbox border="-2147483648" converter="org.jboss.seam.ui.converter.EntityConverter@1d11c30" disabled="false" id="j_id1" immediate="false" localValueSet="false" readonly="false" rendered="true" required="false" transient="false" valid="true"><HtmlSelectItems hideNoSelectionLabel="false" id="j_id2" label="" rendered="true" transient="false" var="crs"/></HtmlSelectManyCheckbox></HtmlForm></AjaxViewRoot
            - Scoped Variables
            Request Parameters Name Value 
            None 
            Request Attributes Name Value 
            ajaxContext org.ajax4jsf.context.AjaxContextImpl@e6e36 
            Session Attributes Name Value 
            course englearn.elc.Course@1d25f53 
            Application Attributes Name Value 
            None 
            



            • 3. Re: Checkboxes should be easy right?
              ericjava.eric.chiralsoftware.net

              I'm not really sure what's going on, but you are getting a NPE.  Are you sure that the value of #{CourseListSeam.courses} is non-null?


              Here's an example of selectMany, taken straight from my code, which is working properly, in production:


                                      <h:selectManyCheckbox value="#{prospectManager.selectedProspectNotes}"
                                                            id="notes">
                                          <s:selectItems value="#{prospectManager.followupPending}"
                                                         var="pn"
                                                         label="#{pn.note}"/>
                                          <s:convertEntity />
                                      </h:selectManyCheckbox>



              The value of #{prospectManager.followupPending} and #{prospectManager.selectedProspectNotes} are both Lists.  This whole thing works beautifully.


              This is with Seam 2 and the standard JSF implementation that comes with JBoss AS.

              • 4. Re: Checkboxes should be easy right?
                theseamnewbie

                Yes, I'm sure that I have something in my db. I just added println to see the size and here is what I've got:



                Hibernate: select course0_.COURSE_ID as COURSE1_0_, course0_.COURSE_ACRONYM as COURSE2_0_, course0_.COURSE_CONTENT_URL as COURSE3_0_, course0_.COURSE_DURATION as COURSE4_0_, course0_.COURSE_EMS_ACRONYM as COURSE5_0_, course0_.COURSE_FULL_NAME as COURSE6_0_, course0_.COURSE_PORTAL_URL as COURSE7_0_, course0_.COURSE_VC_URL as COURSE8_0_ from EL_COURSE course0_ order by course0_.COURSE_ID
                
                I'm IN getCourses()--- the size of array is: 2
                
                Jul 22, 2008 10:09:14 PM com.sun.facelets.FaceletViewHandler handleRenderException
                SEVERE: Error Rendering View[/ddlTest.xhtml]
                javax.faces.FacesException: Exception while calling encodeEnd on component : {Component-Path : [Class: org.ajax4jsf.component.AjaxViewRoot,ViewId: /ddlTest.xhtml][Class: javax.faces.component.html.HtmlForm,Id: j_id0][Class: javax.faces.component.html.HtmlSelectManyCheckbox,Id: j_id1]}
                     at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:559)




                Those are two three lines of my server log.
                the testing output is in getCourses() function (CourseListAction.java).


                Any idea why this happens?

                • 5. Re: Checkboxes should be easy right?
                  damianharvey.damianharvey.gmail.com

                  So your list of courses is taken from #{CourseListSeam.courses} and you are writing any of them that are selected to a Bean property called #{CourseListSeam.courses}? -ie. the same property?


                  What you need is a list to take the values from, and a separate list to populate with your selections.


                  You'll need <s:convertEntity/> but change your PersistenceContext to the Seam Managed one first or you'll no doubt run into problems (like your NPE). Read the reference on convertEntity.


                  Cheers,


                  Damian.


                  • 6. Re: Checkboxes should be easy right?
                    theseamnewbie

                    Do you know where I can find an example of how to set up a Seam Managed PersistenceContext using Geronimo?


                    I'm also using seam 2.1, should I be using 2.0.2?