5 Replies Latest reply on Aug 25, 2011 5:10 AM by badeddin

    Unable to get the Value of ComboBox

    badeddin

      Hello, I have a table QuestionReponse and it contains an Object Reponse which representes a foreign key to the Table Reponse, I want to use a ComboBox to choose the Reponse object to put it in the QuestionReponse Table.
      There is the code I used for the ComboBox


                                     


      <h:selectOneMenu value="#{selectedReponse}" id="selectedReponse"
                               style=" width : 303px;">
                               <f:selectItem itemLabel="#{questionreponseHome.instance.reponse}"
                                    itemValue="" />
                               <s:selectItems value="#{reponseAction.initReponseToTrack()}"
                                    var="_reponse" label="#{_reponse.reponse}" />
                               <s:convertEntity />
                               <a:support event="onchange" action="#{reponseAction.test()}" />
                          </h:selectOneMenu>



      And for the bean there is the code:




      @Scope(ScopeType.PAGE)
      @Name("reponseAction")
      public class ReponseActionBean implements Serializable {
      
           /**
            * 
            */
           private static final long serialVersionUID = 4083573734422505830L;
      
           @In(create = true)
           private ReponseList reponseList;
           
           @In(create = true)
           ReponseHome reponseHome;
           @In(create = true)
           QuestionreponseHome questionreponseHome; 
           
           @DataModel
           private List<Reponse> reponseToTrack = new ArrayList<Reponse>();
      
      
           @Out(required = false)
           @In(required = false)
           @Logger private Log log;
           private Reponse selectedReponse = new Reponse();
      
           @Factory("reponseToTrack")
           public List<Reponse> initReponseToTrack() {
                    reponseToTrack = reponseList.getResultList();
                System.out.println("initReponseToTrack");
                    return reponseToTrack;
           }
           
           public Reponse getSelectedReponse() {
                System.out.println("Get Selected Reponse");
                
                if (this.selectedReponse != null) {
                     
                     log.info(">>>>> get getSelectedReponse selectedReponse = "
                               + this.selectedReponse.getReponse());
                     }
                     
                return this.selectedReponse;
           }
           
      
           public void setSelectedReponse(Reponse reponse) {
                
                System.out.println("Set Selected Reponse");
                this.selectedReponse = reponse;
           }
      
           public void test() {
                System.out.println("test");
                System.out.println(selectedReponse == null ? "null" : selectedReponse.getIdreponse());
                   reponseHome.getInstance().setIdreponse(selectedReponse.getIdreponse());
           }
      }
      



      I noticed that in each call of the Test Method selectedReponse is null.


      Please help me, I can't go forward in my project without your help.


      Thank You


        • 1. Re: Unable to get the Value of ComboBox
          cosmo

          Try changing this


          @Out(required = false)
          @In(required = false)
          @Logger private Log log;
          private Reponse selectedReponse = new Reponse();



          to this


          @Logger private Log log;
          @Out(required = false)
          @In(required = false)
          private Reponse selectedReponse;


          • 2. Re: Unable to get the Value of ComboBox
            badeddin

            Thank you for your reply, it works now the selectedReponse is no longer null, but when I do questionreponseHome.persist the chosen Reponse is not set on the database.
            Here is the code I'm using




            <h:form>
            
                           <s:decorate id="commentaireField" template="layout/edit.xhtml">
                                <ui:define name="label">Commentaire</ui:define>
                                <rich:inplaceInput
                                     value="#{questionreponseHome.instance.commentaire}" />
                           </s:decorate>
            
            
                           <s:decorate id="ReponseField" template="layout/edit.xhtml">
                                <ui:define name="label">Reponse</ui:define>
                                <h:selectOneMenu value="#{reponseAction.selectedReponse}" id="selectedReponse"
                                     style=" width : 303px;">
                                     <f:selectItem itemLabel="#{questionreponseHome.instance.reponse}"
                                          itemValue="" />
                                     <s:selectItems value="#{reponseAction.initReponseToTrack()}"
                                          var="_reponse" label="#{_reponse.reponse}" />
                                     <s:convertEntity />
                                     <a:support event="onchange" action="#{reponseAction.test()}" />
                                </h:selectOneMenu>
                           </s:decorate>
            
                           <h:commandButton action="#{questionreponseHome.persist}" value="Save" />
                      </h:form>




            And the code for the ActionBean is now:




            @Scope(ScopeType.PAGE)
            @Name("reponseAction")
            public class ReponseActionBean implements Serializable {
            
                 /**
                  * 
                  */
                 private static final long serialVersionUID = 4083573734422505830L;
            
                 @In(create = true)
                 private ReponseList reponseList;
                 
                 @In(create = true)
                 ReponseHome reponseHome;
                 @In(create = true)
                 QuestionreponseHome questionreponseHome; 
                 
                 @DataModel
                 private List<Reponse> reponseToTrack = new ArrayList<Reponse>();
            
                 @Logger private Log log;
                 @In(required = false)
                 @Out(required = false)
                 private Reponse selectedReponse;
            
                 @Factory("reponseToTrack")
                 public List<Reponse> initReponseToTrack() {
                          reponseToTrack = reponseList.getResultList();
                      System.out.println("initReponseToTrack");
                          return reponseToTrack;
                 }
                 
                 public Reponse getSelectedReponse() {
                      System.out.println("Get Selected Reponse");
                      
                      if (this.selectedReponse != null) {
                           
                           log.info(">>>>> get getSelectedReponse selectedReponse = "
                                     + this.selectedReponse.getReponse());
                           }
                           
                      return this.selectedReponse;
                 }
                 
            
                 public void setSelectedReponse(Reponse reponse) {
                      
                      System.out.println("Set Selected Reponse");
                      this.selectedReponse = reponse;
                 }
            
                 public void test() {
                      System.out.println("test");
                      System.out.println(selectedReponse == null ? "null" : selectedReponse.getIdreponse());
                     reponseHome.getInstance().setIdreponse(selectedReponse.getIdreponse());
                 }
            }



            Sorry for bothering you again.
            Thank you for your time.





            • 3. Re: Unable to get the Value of ComboBox
              badeddin

              I could get this to work by adding the code below in the test method:




              questionreponseHome.getInstance().setReponse(selectedReponse);



              Now I want to use the Reponse Bean I made to do Inline Editing, but I keep getting an exception


              There is what I am using for the xhtml page:




                   <ui:define name="body">
                   <h:form>
                <rich:dataTable value="#{questionreponseList.resultList}" var="_qr" rows="10">
                  <rich:column>
                    <rich:inplaceInput value="#{_qr.commentaire}" />
                  </rich:column>
                  <rich:column>
                  <h:selectOneMenu value="#{reponseAction.selectedReponse}" id="selectedReponse"
                                       style=" width : 303px;">
                                       <f:selectItem itemLabel="#{questionreponseHome.instance.reponse}"
                                            itemValue="" />
                                       <s:selectItems value="#{reponseAction.initReponseToTrack()}"
                                            var="_reponse" label="#{_reponse.reponse}" />
                                       <s:convertEntity />
                                       <a:support event="onchange" action="#{reponseAction.test()}" />
                                  </h:selectOneMenu>
                             </rich:column>
                  <f:facet name="footer">
                    <rich:datascroller maxPages="5" />
                  </f:facet>
                </rich:dataTable>
                <h:commandButton action="#{questionreponseHome.update}" value="Save"/>
              </h:form>



              And this is the exception I get:




              javax.el.ELException: java.lang.NullPointerException
                   at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:339)
                   at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:280)
                   at org.jboss.el.parser.AstMethodSuffix.getValue(AstMethodSuffix.java:59)
                   at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
                   at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
                   at com.sun.facelets.el.ELText$ELTextVariable.toString(ELText.java:174)
                   at com.sun.facelets.el.ELText$ELTextComposite.toString(ELText.java:115)
                   at com.sun.facelets.compiler.CommentInstruction.write(CommentInstruction.java:38)
                   at com.sun.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:39)
                   at com.sun.facelets.compiler.UILeaf.encodeAll(UILeaf.java:149)
                   at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
                   at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
                   at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
                   at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
                   at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
                   at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
                   at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
                   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                   at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                   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:178)
                   at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                   at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
                   at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
                   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:60)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
                   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
                   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
                   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                   at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
                   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
                   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
                   at java.lang.Thread.run(Unknown Source)
              Caused by: java.lang.NullPointerException
                   at org.domain.test.session.ReponseActionBean.test(ReponseActionBean.java:76)
                   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                   at java.lang.reflect.Method.invoke(Unknown Source)
                   at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
                   at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                   at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                   at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                   at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                   at org.jboss.seam.core.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:32)
                   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:185)
                   at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
                   at org.domain.test.session.ReponseActionBean_$$_javassist_seam_13.test(ReponseActionBean_$$_javassist_seam_13.java)
                   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                   at java.lang.reflect.Method.invoke(Unknown Source)
                   at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)



              Please help!
              Thank You.






              • 4. Re: Unable to get the Value of ComboBox
                badeddin

                I got ride of the exception by changing the test method to this:




                public void test() {
                          System.out.println("test");
                          System.out.println(selectedReponse == null ? "null" : selectedReponse.getIdreponse());
                          if(selectedReponse!=null)
                          {
                         reponseHome.getInstance().setIdreponse(selectedReponse.getIdreponse());
                         questionreponseHome.getInstance().setReponse(selectedReponse);
                          }
                     }



                I am able now to choose the Reponse in each row but after clicking on the save button the other values in the database are updated but not the REPONSE value, what should I do?


                I'm waiting for your replies Seamers, Please Help!


                Thank you for helping me.





                • 5. Re: Unable to get the Value of ComboBox
                  badeddin

                  Hello, I solved the problem I was facing and if anyone needs it here is what I have changed:




                  <h:selectOneMenu value="#{_qr.reponse}" id="selectedReponse"
                                           style=" width : 303px;">
                                           <f:selectItem itemLabel="#{questionreponseHome.instance.reponse.reponse}"
                                                itemValue="" />
                                           <s:selectItems value="#{reponseAction.initReponseToTrack()}"
                                                var="_reponse" label="#{_reponse.reponse}" />
                                           <s:convertEntity />
                                           <a:support event="onchange" action="#{reponseAction.test()}" />
                                      </h:selectOneMenu>



                  Thank you for help Seamers.