2 Replies Latest reply on May 23, 2014 3:49 AM by matthiasgerhards

    Boolean values in backing bean are (unexpectedly) initialized after ajax call

    matthiasgerhards

      Hi All,

      I am new to this forum and hope that this is the right place for my question/issue. I am posting this her,e because I am not shure if it is an issue or not.


      Situation:

      I am migrating my rich faces 4.3.6 application from glassfish to tomcat Apache Tomcat/7.0.53. I have an interesting
      issue with the a4j:ajax feature and the h:selectOneMenu.

       

      Problem:

      If an ajax event is processed the jsf/rich faces seems to initialize every boolean attribute of my backing
      beans with an initial value = false. Only if excecute and render are @form. Has anybody experienced something like that before?

       

      The user never clicked one the component and the value should still be null.

      I used Boolean and not the primitive type boolean in my backing bean.

       

      My example facelet looks like this:
      -----------------------------------------------------------------
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "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:a4j="http://richfaces.org/a4j"
            xmlns:rich="http://richfaces.org/rich">

      <h:head>
         <title><ui:insert name="title">Tomcat test init issue</ui:insert></title>
      </h:head>
      <h:body>
      <h:form id="avaro">
      <h:selectOneRadio id="firstSelect" 
             value="#{myTestBean.firstBooleanValue}">
        <f:converter converterId="javax.faces.Boolean"/>       
        <f:selectItem itemLabel="True" itemValue="true" />        
        <f:selectItem itemLabel="False" itemValue="false" />
        <a4j:ajax event="click"
            render="@form"
            execute = "@form"
        />
      </h:selectOneRadio>

      <h:selectOneRadio id="secondSelect" 
             value="#{myTestBean.secondBooleanValue}">
        <f:converter converterId="javax.faces.Boolean"/>       
        <f:selectItem itemLabel="True" itemValue="true" />        
        <f:selectItem itemLabel="False" itemValue="false" />
      </h:selectOneRadio>
      </h:form>
      </h:body>
      </html>

       

      My Backing bean looks like this:
      --------------------------------------------------------

      package de.dvka.avaro.frontend.jsf.beans;

      import java.io.Serializable;
      import javax.enterprise.context.SessionScoped;
      import javax.inject.Named;


      @Named ("myTestBean")
      @SessionScoped
      public class MyTestBean implements Serializable{

      private static final long serialVersionUID = 3475839275576533364L;
      Boolean firstBooleanValue;
      Boolean secondBooleanValue;

      public Boolean getFirstBooleanValue() {
        return firstBooleanValue;
      }
      public void setFirstBooleanValue(Boolean firstBooleanValue) {
        this.firstBooleanValue = firstBooleanValue;
      }
      public Boolean getSecondBooleanValue() {
        return secondBooleanValue;
      }
      public void setSecondBooleanValue(Boolean secondBooleanValue) {
        this.secondBooleanValue = secondBooleanValue;
      }
      }

       


      The relevant parts of my pom are:

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

      ...
      <plugin>
         <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
               <source>1.6</source>
                   <target>1.6</target>
              </configuration>
      </plugin>
      ...

      <properties>
            <spec.snapshot.version>2.2-m12</spec.snapshot.version>
            <org.richfaces.bom.version>4.3.6.Final</org.richfaces.bom.version>
      </properties>
      ...
      <dependencyManagement>
      <dependencies>
        <dependency>
         <groupId>org.richfaces</groupId>
         <artifactId>richfaces-bom</artifactId>
         <version>${org.richfaces.bom.version}</version>
         <scope>import</scope>
         <type>pom</type>
        </dependency> 
      </dependencies>
      </dependencyManagement>
      ...
      <dependencies>
      <dependency>
        <groupId>javax.faces</groupId>
        <artifactId>javax.faces-api</artifactId>
        <version>2.2-m12</version><!--$NO-MVN-MAN-VER$-->
      </dependency>
      <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId> 
      </dependency>
      <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.faces</artifactId>
      </dependency>
      <dependency>
        <groupId>org.jboss.spec.javax.faces</groupId>
        <artifactId>jboss-jsf-api_2.1_spec</artifactId>  
      </dependency>
      <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>org.richfaces.ui</groupId>
        <artifactId>richfaces-components-ui</artifactId>
      </dependency>
      <dependency>
        <groupId>org.richfaces.core</groupId>
        <artifactId>richfaces-core-impl</artifactId>
      </dependency>
      <dependency>
        <groupId>org.jboss.weld.servlet</groupId>
        <artifactId>weld-servlet</artifactId>
        <version>2.2.0.SP1</version>
      </dependency>
      <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
      </dependency>
        <dependency>
         <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.0.Final</version>
      </dependency>
      <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-core</artifactId>
        <version>2.2.7.Final</version>
      </dependency>
      <dependency>
        <groupId>org.atmosphere</groupId>
        <artifactId>atmosphere-jersey</artifactId>
        <version>1.0.10</version>
      </dependency>