7 Replies Latest reply on Dec 6, 2007 5:48 AM by norbert45fr

    simple reRender action does not work

    norbert45fr

      Hello all,
      That's now couple of days I'm trying to do something that seems quite simple for everyone but it's not working at all. I have read lot of manuals, forum treads, etc but with no success on result.
      Description of my problem: I would like to display a value selected in an h:selectOneMenu but nothing is rendered. This is a simple test to try to understand because mi final objective is to hide/show an object base upon selection, but displaying the selection is not working already.

      Here is my code:

      <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
      <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
      <html>
      <head>
      <title>test</title>
      </head>
      <body>
      <f:view locale="en_US">
       <h:form>
       <h:messages layout="table"></h:messages>
       <h:selectOneMenu id="searchperiod" immediate="true" value="#{solution.selectedPeriod}">
       <a4j:support event="onchange" reRender="periodgrid" immediate="true" />
       <f:selectItems value="#{solution.periodList}" />
       </h:selectOneMenu>
       <h:outputText value="value selected: #{solution.selectedPeriod}" id="periodgrid"></h:outputText>
       </h:form>
       <a4j:log level="DEBUG" popup="false" />
      </f:view>
      </body>
      </html>


      package com.test.Beans;
      
      import java.util.ArrayList;
      
      import javax.faces.component.UISelectOne;
      import javax.faces.component.UIViewRoot;
      import javax.faces.context.FacesContext;
      import javax.faces.model.SelectItem;
      
      public class Solution {
       enum Periods { ALL, LAST_10_DAYS, LAST_30_DAYS, LAST_90_DAYS, LAST_YEAR, CUSTOM };
       private String selectedPeriod = null;
       private ArrayList<SelectItem> periodList = null;
       private String isVisible = "false";
      
       public Solution() {
       super();
       }
      
       public String getSelectedPeriod() {
       return selectedPeriod;
       }
      
       public void setSelectedPeriod(String selectItem) {
       this.selectedPeriod = selectItem;
       }
      
       public ArrayList<SelectItem> getPeriodList() {
       if (periodList == null) {
       periodList = new ArrayList<SelectItem>();
       periodList.add(new SelectItem(Solution.Periods.ALL, "All Time") ) ;
       periodList.add(new SelectItem(Solution.Periods.LAST_10_DAYS, "Last 10 days") ) ;
       periodList.add(new SelectItem(Solution.Periods.LAST_30_DAYS, "Last 30 days") ) ;
       periodList.add(new SelectItem(Solution.Periods.LAST_90_DAYS, "Last 90 days") ) ;
       periodList.add(new SelectItem(Solution.Periods.LAST_YEAR, "Last year") ) ;
       periodList.add(new SelectItem(Solution.Periods.CUSTOM, "Custom period") ) ;
       setIsVisible("false");
       }
       return periodList;
       }
      
       public void setPeriodList(ArrayList<SelectItem> periodList) {
       this.periodList = periodList;
       }
      
      
       public String getIsVisible() {
       return isVisible;
       }
      
       public void setIsVisible(String isVisible) {
       this.isVisible = isVisible;
       }
      }
      


      <?xml version="1.0" encoding="UTF-8"?>
      
      <faces-config
       xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
       version="1.2">
       <application>
       <locale-config>
       <default-locale>en_US</default-locale>
       <supported-locale>en</supported-locale>
       </locale-config>
       </application>
       <managed-bean>
       <managed-bean-name>
       solution</managed-bean-name>
       <managed-bean-class>
       com.test.Beans.Solution</managed-bean-class>
       <managed-bean-scope>
       session</managed-bean-scope>
       </managed-bean>
      </faces-config>
      


      I'm using Eclipse Europa and publish the code to JBoss 4.2.1.GA with Java 1.5_012. I have in lib commons-beanutils-cor. jar, commons-beanutils.jar, commons-beanutils-bean-collections.jar, common-digester-1.8.jar, richfaces-ui-3.1.2.GA.jar, richfaces-api-3.1.2.GA.jar, richfaces-impl-3.1.2.GA.jar, standard.jar, jstl.jar, jsf-impl.jar, jsf-api.jar, phaseTracker.jar and all the JBoss jar

      Here is the show/hide I would like to do in final:
      <rich:panel header="Search within a period">
       <h:panelGrid style="width: 100%; top: auto;">
       <h:selectOneMenu id="SearchPeriod" immediate="true" value="#{solution.selectedPeriod}">
       <a4j:support event="onchange" reRender="periodgrid" immediate="true" />
       <f:selectItems value="#{solution.periodList}" />
       </h:selectOneMenu>
       <a4j:region>
       <a4j:outputPanel id="periodgrid">
       <h:panelGrid id="PeriodGrid2" columns="2" style="width: 100%; vertical-align: top;" rendered="#{solution.selectedPeriod} == 'CUSTOM'">
       <h:outputText id="FromDateLabel" value="From: " />
       <rich:calendar id="FromDate" datePattern="dd-MMM-yyyy" />
       <h:outputText id="ToDateLabel" value="To: " />
       <rich:calendar id="ToDate" datePattern="dd-MMM-yyyy" />
       </h:panelGrid>
       </a4j:outputPanel>
       </a4j:region>
       </h:panelGrid>
      </rich:panel>
      


      Does some one can help?
      Thanks a lot

        • 1. Re: simple reRender action does not work
          sebgerpb

          Hi norbert,

          I'm not sure if I unterstand your problem correctly, but did you try

          <a4j:support event="onselect" reRender="periodgrid" immediate="true" />
          


          yet?

          • 2. Re: simple reRender action does not work
            norbert45fr

            thanks sebgerpb. Yes I have tried onselect and I have the same problem, nothing display By the way I take a look at the HTML generated

            <html>
            <head>
            <title>repeater</title>
            <script type='text/javascript' src='/myJBoss/faces/a4j_3_1_2.GAorg.ajax4jsf.javascript.AjaxScript'></script></head>
            <body>
            
            <form id="j_id_jsp_985180959_1" name="j_id_jsp_985180959_1" method="post" action="/myJBoss/faces/Solution.jsp" enctype="application/x-www-form-urlencoded">
            <input type="hidden" name="j_id_jsp_985180959_1" value="j_id_jsp_985180959_1" />
            <select id="j_id_jsp_985180959_1:searchperiod" name="j_id_jsp_985180959_1:searchperiod" size="1" onselect="A4J.AJAX.Submit('j_id_jsp_985180959_0','j_id_jsp_985180959_1',event,{'parameters':{'j_id_jsp_985180959_1:j_id_jsp_985180959_4':'j_id_jsp_985180959_1:j_id_jsp_985180959_4'} ,'actionUrl':'/myJBoss/faces/Solution.jsp'} )"> <option value="ALL">All Time</option>
            
             <option value="LAST_10_DAYS">Last 10 days</option>
             <option value="LAST_30_DAYS">Last 30 days</option>
             <option value="LAST_90_DAYS">Last 90 days</option>
             <option value="LAST_YEAR">Last year</option>
             <option value="CUSTOM">Custom period</option>
            </select><span id="j_id_jsp_985180959_1:periodgrid">value selected: </span><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="_id5" />
            
            </form><div id="logConsole" style="width:800;height:600;overflow:auto;"><script type="text/javascript">LOG.LEVEL = LOG.DEBUG;</script></div>
            </body>
            </html>


            and I do not understand
            <span id="j_id_jsp_985180959_1:periodgrid">value selected: </span><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="_id5" />


            I think I have read somewhere that the input field must be surrounded by span so that data is rendered.



            • 3. Re: simple reRender action does not work
              norbert45fr

              anyone cal help on this one?
              Thanks

              • 4. Re: simple reRender action does not work
                ilya_shaikovsky

                you sure that from server values returns correct? Do you see any problems in a4j:log output?

                • 5. Re: simple reRender action does not work
                  norbert45fr

                  thanks ilya,
                  Well, since it was not working at all I have recreated everything from scratch and really nothing is working. I'm even not able to deploy anymore my application to JBoss.
                  Does someone has a simple example I can plug in eclipse and run on a
                  JBoss server 4.2.1.GA?

                  Thanks

                  • 6. Re: simple reRender action does not work
                    norbert45fr

                    this is nightmare!
                    Yesterday I've started over and I was not able to deploy.
                    Today it deploys but reRender does not work.
                    In fact it does not work in client mode, but if I click on submit button, page is refreshed and result displayed.

                    <tr>
                     <td nowrap="nowrap" valign="middle" width="1%">Date Range:</td>
                     <td width="99%">
                     <h:selectOneMenu id="searchperiod" immediate="true" value="#{solution.selectedPeriod}">
                     <f:selectItems value="#{solution.periodList}" />
                     </h:selectOneMenu>
                     <h:outputText value="value selected: #{solution.selectedPeriod}" id="periodgrid" escape="true" /></td>
                    </tr>
                    


                    and <a4j:log level="DEBUG" popup="false" /> does not work
                    any help is appriciated

                    • 7. Re: simple reRender action does not work
                      norbert45fr

                      in my previous email a4j:support was missing -- error form cut and paste.

                      Any way, it's magically working now.
                      Difference are:
                      - I have loaded richfaces-ui-3.1.2.SP1-bin.zip (latest)
                      - removed all jar files except richfaces ones and apache commons
                      - change my code as follow

                      <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
                      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
                      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
                      <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
                      <html>
                      <head>
                      <meta http-equiv="content-type" content="text/html">
                      <title>Search knowledge base</title>
                      </head>
                      <body leftmargin="10" rightmargin="10" topmargin="0">
                      <f:view locale="en_US">
                       <rich:message></rich:message>
                       <a4j:form>
                       <rich:panel>
                       <f:facet name="header">Search knowledge base</f:facet>
                       <h:panelGrid border="1" columns="2">
                       <h:outputText value="Search:"></h:outputText>
                       <h:inputText size="80"></h:inputText>
                       <h:outputText value="Date Range:"></h:outputText>
                       <h:selectOneMenu id="searchperiod" immediate="true" value="#{solution.selectedPeriod}">
                       <f:selectItems value="#{solution.periodList}" />
                       <a4j:support event="onchange" reRender="periodgrid" />
                       </h:selectOneMenu>
                       <h:outputText value="Results Per Page:"></h:outputText>
                       <select size="1" name="numResults" id="results01">
                       <option value="10">10</option>
                       <option value="15" selected="selected">15</option>
                       <option value="30">30</option>
                       <option value="50">50</option>
                       <option value="100">100</option>
                       </select>
                       <h:commandButton></h:commandButton>
                       </h:panelGrid>
                       <a4j:outputPanel ajaxRendered="true">
                       <h:outputText value="value selected: #{solution.selectedPeriod}" id="periodgrid"/>
                       <a4j:log level="DEBUG" popup="false" />
                       </a4j:outputPanel>
                       </rich:panel>
                       </a4j:form>
                      </f:view>
                      </body>
                      </html>

                      and published on my server

                      this is now working!