12 Replies Latest reply on Sep 2, 2008 10:46 AM by julienc

    Problem with <A4j:support /> on <h:selectOneMenu  rendered=f

    julienc

      hello everybody,

      I have a h:selectOneMenu with a rendered=false to load the page.

      On this selectOneMenu i have an A4j:support with event=onchange and a reRender=ID.

      If we start with rendered=true on selectOneMenu, all is working correctly, but if the rendered=false ID is not reRender and the value of selectOneMenu isn't pass to the bean.

      start with rendered=true => rendered=false => rendered=true ... => all is working

      start with rendered=false => rendered=true => rendered=false ... => in this case no value and no rerender is done.



      <h:selectOneMenu rendered="#{statistics.isVisible()}" id="service" value="#{statistics.selected}">
      <c:forEach var="wap" items="#{listservice.waps}">
      <f:selectItem itemValue="#{wap}" itemLabel="#{wap}" />
      </c:forEach>
      <a4j:support event="onchange" reRender="stats" />
      </h:selectOneMenu>
      


      For the fist page display isVisible return false.

      After that another selectOneMenu change the value of visible and reRender service, so isVisible return true and the component is diplaying.
      but the reRender of stats doesn't work if the value change.

      If with start to display "service" (isVisible return true and change to false then change to true ... ) it's working.

      Any ideas ?

      Thanks.

      Julien



        • 1. Re: Problem with <A4j:support /> on <h:selectOneMenu  render
          mail.micke

          Hi

          You should wrap the selectOneMenu in for example a a4j:output and then rerender the a4j:output.

          The reason for this is that the second selectOneMenu isn't displayed is because there is nothing in the DOM to display, since it wasn't rendered nothing is found to reRender.

          That is why you have the a4j:output , which is invisible, to reRender.

          Hope this helps,
          micke

          • 2. Re: Problem with <A4j:support /> on <h:selectOneMenu  render
            julienc

            I'll try to explain better.

            the diplaying of selectOneMenu is always working.

            The problem is if we start with a rendered=false then pass to rendered=true ...

            <a4j:support event="onchange" reRender="stats" />
            looks to not work (no reRender, no value change) but the selectOneMenu is displaying.

            however, if we start with rendered=true then pass to rendered=false then true... in this case all is working correctly.

            In html debug mode, there is post in two cases but the response is different. (when it works we get all the page otherwise we get the page with empty body)

            • 3. Re: Problem with <A4j:support /> on <h:selectOneMenu  render
              mail.micke

              Ok,
              I thought there was one selectOneMenu which caused another one to be displayed.

              I believe you can solve this with solution I proposed. If rendered=false to begin with it won't be present in the DOM, at least this is what I think.

              <a4j:outputPanel layout="inline" id="menuWrapper">
              <h:selectOneMenu rendered="#{statistics.isVisible()}" id="service" value="#{statistics.selected}">
              <c:forEach var="wap" items="#{listservice.waps}">
              <f:selectItem itemValue="#{wap}" itemLabel="#{wap}" />
              </c:forEach>
              <a4j:support event="onchange" reRender="stats" />
              </h:selectOneMenu>
              </a4j:outputPanel>
              


              In your a4j:support you reRender "menuWrapper", give this a go and see if it helps.

              (And I meant a4j:outputPanel and not a4j:output :) )


              • 4. Re: Problem with <A4j:support /> on <h:selectOneMenu  render
                julienc

                Nothing change.

                I tried with an s:div before and with <a4j:outputPanel> it's the same.

                I thought before the javascript was not generated if rendered was equal to false but it's generated in the source in 2 cases. but something happen when to start the rendered=false :/

                • 5. Re: Problem with <A4j:support /> on <h:selectOneMenu  render
                  mail.micke

                  I noticed that i wrapped the selectOneMenu which seems to be used for rendering something else called "stats".

                  What is the "stats" thing? And that is the one which should be wrapped with an a4j:outputPanel.

                  If you don't fix it, please post all the relevant code.

                  -micke

                  • 6. Re: Problem with <A4j:support /> on <h:selectOneMenu  render
                    julienc

                    stats is an a4j:form which is containing all.

                    • 7. Re: Problem with <A4j:support /> on <h:selectOneMenu  render
                      julienc

                      I have create an example to reproduce the bug.

                      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                       xmlns:s="http://jboss.com/products/seam/taglib"
                       xmlns:ui="http://java.sun.com/jsf/facelets"
                       xmlns:f="http://java.sun.com/jsf/core"
                       xmlns:h="http://java.sun.com/jsf/html"
                       xmlns:rich="http://richfaces.org/rich"
                       xmlns:a4j="http://richfaces.org/a4j"
                       xmlns:c="http://java.sun.com/jstl/core"
                       template="../layout/template.xhtml">
                      
                      
                       <ui:define name="body">
                       <rich:panel>
                       <a4j:form id="ServiceForm">
                       <h:outputText value="#{service.selectedService}" id="test"></h:outputText>
                       <h:outputText value="#{service.selectedService2}" id="test2"></h:outputText>
                       <h:outputText value="#{service.selectedService4}" id="test4"></h:outputText>
                      
                       <h:selectOneMenu id="service" value="#{service.selectedService}">
                       <f:selectItem itemLabel="service" itemValue="service" />
                       <f:selectItem itemLabel="service1" itemValue="service1" />
                       <a4j:support event="onchange" reRender="ServiceForm"/>
                       </h:selectOneMenu>
                      
                       <h:selectOneMenu rendered="#{service.isService1()}" id="service2" value="#{service.selectedService2}">
                       <f:selectItem itemLabel="service2" itemValue="service2" />
                       <f:selectItem itemLabel="service3" itemValue="service3" />
                       <a4j:support event="onchange" reRender="ServiceForm" />
                       </h:selectOneMenu>
                      
                       <h:selectOneMenu rendered="#{service.isService3()}" id="service4" value="#{service.selectedService4}">
                       <f:selectItem itemLabel="service4" itemValue="service4" />
                       <f:selectItem itemLabel="service5" itemValue="service5" />
                       <a4j:support event="onchange" reRender="ServiceForm" />
                       </h:selectOneMenu>
                       </a4j:form>
                       </rich:panel>
                       </ui:define>
                      
                      </ui:composition>
                      


                      package eu.mpulse.admin.analitycs;
                      
                      import java.io.Serializable;
                      
                      import org.jboss.seam.annotations.Name;
                      
                      @Name("service")
                      public class Service implements Serializable{
                      
                       private static final long serialVersionUID = 6902569620231028811L;
                       public String selectedService = "service";
                       public String selectedService2 = "service2";
                       public String selectedService4 = "service4";
                      
                      
                       public boolean isService1(){
                       return "service1".equals(selectedService);
                       }
                      
                       public boolean isService3(){
                       return "service3".equals(selectedService2);
                       }
                      
                       public String getSelectedService() {
                       return selectedService;
                       }
                       public void setSelectedService(String selectedService) {
                       this.selectedService = selectedService;
                       }
                       public String getSelectedService2() {
                       return selectedService2;
                       }
                       public void setSelectedService2(String selectedService2) {
                       this.selectedService2 = selectedService2;
                       }
                       public String getSelectedService4() {
                       return selectedService4;
                       }
                       public void setSelectedService4(String selectedService4) {
                       this.selectedService4 = selectedService4;
                       }
                      
                      }
                      


                      • 8. Re: Problem with <A4j:support /> on <h:selectOneMenu  render
                        mail.micke

                        Hi

                        Try adding a rich:messages to make sure there isn't a validation error, you never know.

                        Also add an a4j:log to check what happens with the ajax request, you should be able to see here what gets updated.

                        Btw what is the default scope in Seam? Conversation? You could also try Seam's PAGE scope just to make sure the state is kept over many requests.

                        - micke

                        • 9. Re: Problem with <A4j:support /> on <h:selectOneMenu  render
                          julienc

                          This is log.

                          debug[12:35:35,340]: Have Event [object Object] with properties: target: [object HTMLSelectElement], srcElement: undefined, type: change
                          debug[12:35:35,341]: NEW AJAX REQUEST !!! with form :ServiceForm
                          debug[12:35:35,341]: Append select-one control ServiceForm:service with value [service1] and value attribute [null]
                          debug[12:35:35,341]: Append select-one control ServiceForm:service2 with value [service2] and value attribute [null]
                          debug[12:35:35,341]: Append hidden control ServiceForm with value [ServiceForm] and value attribute [ServiceForm]
                          debug[12:35:35,342]: Append hidden control autoScroll with value [] and value attribute []
                          debug[12:35:35,342]: Append hidden control javax.faces.ViewState with value [j_id8] and value attribute [j_id8]
                          debug[12:35:35,342]: parameter ServiceForm:j_id22 with value ServiceForm:j_id22
                          debug[12:35:35,342]: Start XmlHttpRequest
                          debug[12:35:35,342]: Reqest state : 1
                          debug[12:35:35,343]: QueryString: AJAXREQUEST=_viewRoot&ServiceForm%3Aservice=service1&ServiceForm%3Aservice2=service2&ServiceForm=ServiceForm&autoScroll=&javax.faces.ViewState=j_id8&ServiceForm%3Aj_id22=ServiceForm%3Aj_id22&
                          debug[12:35:35,345]: Reqest state : 1
                          debug[12:35:35,388]: Reqest state : 2
                          debug[12:35:35,389]: Reqest state : 3
                          debug[12:35:35,389]: Reqest state : 4
                          debug[12:35:35,389]: Reqest end with state 4
                          debug[12:35:35,389]: Response with content-type: text/xml;charset=UTF-8
                          debug[12:35:35,389]: Full response content: <?xml version="1.0"?> <html xmlns="http://www.w3.org/1999/xhtml"><head><link type="text/css" rel="stylesheet" href="/UniversalAdmin/a4j_3_2_0.SR1-SNAPSHOTorg/richfaces/renderkit/html/css/basic_classes.xcss/DATB/eAF7seFCOQAHywLg" class="component" />
                          <link type="text/css" rel="stylesheet" href="/UniversalAdmin/a4j_3_2_0.SR1-SNAPSHOTorg/richfaces/renderkit/html/css/extended_classes.xcss/DATB/eAF7seFCOQAHywLg" class="component" />
                          <link type="text/css" rel="stylesheet" href="/UniversalAdmin/a4j_3_2_0.SR1-SNAPSHOTcss/panel.xcss/DATB/eAF7seFCOQAHywLg" class="component" />
                          <link type="text/css" rel="stylesheet" href="/UniversalAdmin/stylesheet/theme_mpulse.css" class="user" />
                          <link type="text/css" rel="stylesheet" href="/UniversalAdmin/stylesheet/theme_mpulse_datatable.css" class="user" />
                          <link type="text/css" rel="stylesheet" href="/UniversalAdmin/stylesheet/theme_mpulse_calendar.css" class="user" />
                          <script type="text/javascript" src="/UniversalAdmin/a4j_3_2_0.SR1-SNAPSHOTorg.ajax4jsf.javascript.AjaxScript">
                          </script><script type="text/javascript" src="/UniversalAdmin/a4j_3_2_0.SR1-SNAPSHOTorg/ajax4jsf/javascript/scripts/form.js">
                           </script><script type="text/javascript" src="/UniversalAdmin/js/polls.js">
                           </script><meta name="Ajax-Update-Ids" content="" />
                          <title></title></head><body><span id="ajax-view-state">
                          <input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="j_id8" /></span><meta id="Ajax-Response" name="Ajax-Response" content="true" /></body></html>
                          debug[12:35:35,390]: Header Ajax-Expired not found, search in <meta>
                          debug[12:35:35,390]: search for elements by name 'meta' in element #document
                          debug[12:35:35,393]: getElementsByTagName found 2
                          debug[12:35:35,393]: Find <meta name='Ajax-Update-Ids' content=''>
                          debug[12:35:35,393]: Find <meta name='Ajax-Response' content='true'>
                          debug[12:35:35,393]: Header Ajax-Update-Ids not found, search in <meta>
                          debug[12:35:35,393]: search for elements by name 'meta' in element #document
                          debug[12:35:35,396]: getElementsByTagName found 2
                          debug[12:35:35,396]: Find <meta name='Ajax-Update-Ids' content=''>
                          warn[12:35:35,396]: No information in response about elements to replace
                          debug[12:35:35,396]: call getElementById for id= org.ajax4jsf.oncomplete
                          debug[12:35:35,397]: call getElementById for id= ajax-view-state
                          debug[12:35:35,397]: Hidden JSF state fields: [object HTMLSpanElement]
                          debug[12:35:35,397]: Namespace for hidden view-state input fields is undefined
                          debug[12:35:35,397]: search for elements by name 'input' in element span
                          debug[12:35:35,399]: getElementsByTagName found 1
                          debug[12:35:35,399]: Replace value for inputs: 3 by new values: 1
                          debug[12:35:35,399]: Input in response: javax.faces.ViewState
                          debug[12:35:35,400]: Found same input on page with type: hidden
                          debug[12:35:35,400]: search for elements by name 'INPUT' in element span
                          debug[12:35:35,402]: getElementsByTagName found 0
                          debug[12:35:35,402]: Replace value for inputs: 3 by new values: 0
                          debug[12:35:35,402]: call getElementById for id= _A4J.AJAX.focus
                          debug[12:35:35,403]: No focus information in response


                          • 10. Re: Problem with <A4j:support /> on <h:selectOneMenu  render
                            mail.micke

                            Hi

                            Just did a quick test and this works for me:

                            <ui:composition 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:a4j="https://ajax4jsf.dev.java.net/ajax"
                             xmlns:rich="http://richfaces.ajax4jsf.org/rich"
                             xmlns:s="http://jboss.com/products/seam/taglib"
                             template="/WEB-INF/layout/template.xhtml">
                            
                             <ui:param name="title" value="SelectOneMenu reRender test"/>
                            
                             <ui:define name="body">
                            
                             <a4j:form id="theForm">
                             <h:panelGrid columns="1">
                             <h:outputText value="select1 #{srb.selected1}"/>
                             <h:outputText value="select2 #{srb.selected2} : #{srb.firstSelected}"/>
                             <rich:spacer/>
                            
                             <h:selectOneMenu id="select1"
                             value="#{srb.selected1}">
                             <f:selectItem itemLabel="service" itemValue="service" />
                             <f:selectItem itemLabel="service1" itemValue="service1" />
                             <a4j:support event="onchange" reRender="theForm"/>
                             </h:selectOneMenu>
                            
                             <h:selectOneMenu id="select2"
                             rendered="#{srb.firstSelected}"
                             value="#{srb.selected2}">
                             <f:selectItem itemLabel="service2" itemValue="service2" />
                             <f:selectItem itemLabel="service3" itemValue="service3" />
                             <a4j:support event="onchange" reRender="theForm" />
                             </h:selectOneMenu>
                            
                             </h:panelGrid>
                            
                             </a4j:form>
                            
                             </ui:define>
                            </ui:composition>
                            


                            package com.dkib.riskit.sandbox.micke;
                            
                            import org.jboss.seam.ScopeType;
                            import org.jboss.seam.annotations.Name;
                            import org.jboss.seam.annotations.Scope;
                            
                            @Name("srb")
                            @Scope( ScopeType.PAGE)
                            public class SelectRerenderBacking {
                            
                             private String selected1;
                             private String selected2;
                            
                             public boolean isFirstSelected(){
                             return selected1 != null;
                             }
                            
                             public String getSelected1() {
                             return selected1;
                             }
                            
                             public void setSelected1(String selected1) {
                             this.selected1 = selected1;
                             }
                            
                             public String getSelected2() {
                             return selected2;
                             }
                            
                             public void setSelected2(String selected2) {
                             this.selected2 = selected2;
                             }
                            }
                            


                            h:form or a4j:form both works, in my opinion no need for an a4j:form in this case.


                            cheers,
                            micke

                            • 11. Re: Problem with <A4j:support /> on <h:selectOneMenu  render
                              julienc

                              I'll try to add @Scope( ScopeType.PAGE) and my example works then i pass scope to conversation and it works too but by default the scope is in conversation :/

                              Strange.

                              Thanks a lot.


                              • 12. Re: Problem with <A4j:support /> on <h:selectOneMenu  render
                                julienc

                                By default the scope is in Event sorry.