1 Reply Latest reply on Oct 3, 2006 12:47 PM by pmuir

    Backing Bean not being updated

    alpheratz-jb

      Hi all,

      I am trying to build a simple test app with a single page that
      links to a second form page that on submission adds data to be displayed by the first page

      My problem is that the backing entity bean is never updated by the form.

      For example, regardless of whatever I enter into the 'disaster' field,
      when I print its value within the appropriate 'add' method I ALWAYS see
      the initial value:

      22:57:52,620 INFO [DisasterAddAction] Add: disaster: wft

      Code follows.

      I would be VERY grateful for any assistance.

      Thanks

      Alph.

      =======================

      I have a form page home.xhtml which indirectly invokes the problematic
      form:

      ===
      ... excerpt begin

      <t:commandLink action="#{disasterFlow.form}" styleClass="t_cl_class white middle" value="[ + ]"></t:commandLink> Disaster</h:panelGroup></f:facet>
      #{cc.disaster}

      ... excerpt end
      ===

      The sole purpose of DisasterFlow is to kick off to the form page
      /test.xhtml:

      ===
      package dnd;

      import org.jboss.seam.annotations.Name;

      @Name("disasterFlow")
      public class DisasterFlow
      {
      public String form()
      {
      return "/test.xhtml";
      }
      }
      ===

      The test.xhtml page is:

      ===
      <!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:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:t="http://myfaces.apache.org/tomahawk"
      xmlns:s="http://jboss.com/products/seam/taglib">

      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      TEST



      <f:view>
      <h:form>
      <h1>TEST</h1>
      <s:validateAll>
      <h:inputText value="#{disaster.disaster}" />

      <h:inputText value="#{disaster.description}" />
      </s:validateAll>

      <s:link action="#{disasterAdder.add}" value="Add" linkStyle="button" />

      </h:form>
      </f:view>


      ===

      DisasterAdder is a Stateless bean:

      ===
      package dnd.ejb3.session;

      import java.io.Serializable;

      import javax.ejb.Remove;
      import javax.ejb.Stateless;

      import org.hibernate.validator.Valid;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.log.Log;

      import dnd.ejb3.entity.Disaster;

      @Stateless
      @Name("disasterAdder")
      public class DisasterAddAction implements Serializable, DisasterAdder
      {
      private static final long serialVersionUID = 5940066174527954201L;

      @Logger
      private Log log;

      @In(create=true) @Valid
      private Disaster disaster;

      public String add()
      {
      log.info("Add: disaster: " + disaster.getDisaster());

      return "/home.xhtml";
      }

      @Remove
      public void destroy() {}
      }
      ===

      Disaster is an Entity:

      ===

      package dnd.ejb3.entity;

      import static javax.persistence.FetchType.LAZY;
      import static org.jboss.seam.ScopeType.EVENT;

      import java.io.Serializable;
      import java.sql.Timestamp;
      import java.util.Collection;

      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.Id;
      import javax.persistence.Lob;
      import javax.persistence.OneToMany;

      import org.hibernate.validator.Length;
      import org.hibernate.validator.NotNull;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;

      @Entity
      @Name("disaster")
      @Scope(EVENT)
      public class Disaster implements Serializable
      {
      private static final long serialVersionUID = -7111093778919494970L;
      private String disaster;
      private Integer disasterPk;
      private Timestamp creationTimeStamp;
      private String description;
      private Collection referenceCollection;

      public Disaster(String disaster, String description)
      {
      super();
      this.disaster = disaster;
      this.description = description;
      }

      public Disaster()
      {
      this.disaster = "wft";
      this.description = "this is NEVER updated!";
      }

      @Length(min=4,max=32) @NotNull
      public String getDisaster()
      {
      return disaster;
      }

      public void setDisaster(String disaster)
      {
      System.out.println("setDisaster: " + disaster);
      this.disaster = disaster;
      }

      @Id
      @Column(name = "disaster_PK", nullable = false)
      public Integer getDisasterPk()
      {
      return disasterPk;
      }

      public void setDisasterPk(Integer disasterPk)
      {
      this.disasterPk = disasterPk;
      }

      @Column(name = "CREATION_TIME_STAMP")
      public Timestamp getCreationTimeStamp()
      {
      return creationTimeStamp;
      }

      public void setCreationTimeStamp(Timestamp creationTimeStamp)
      {
      this.creationTimeStamp = creationTimeStamp;
      }

      @Lob
      @Length(max=64) @NotNull
      public String getDescription()
      {
      return description;
      }

      public void setDescription(String description)
      {
      this.description = description;
      }

      @OneToMany(fetch=LAZY,mappedBy = "disaster")
      public Collection getReferenceCollection()
      {
      return referenceCollection;
      }

      public void setReferenceCollection(Collection referenceCollection)
      {
      this.referenceCollection = referenceCollection;
      }

      public Reference addReference(Reference reference)
      {
      getReferenceCollection().add(reference);
      reference.setdisaster(this);
      return reference;
      }

      public Reference removeReference(Reference reference)
      {
      getReferenceCollection().remove(reference);
      reference.setdisaster(null);
      return reference;
      }
      }
      ===

      faces-config is:

      ===
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE faces-config
      PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
      "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">

      <faces-config>

      <!-- Facelets support -->


      <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>


      <!-- Select one of the two standard persistence lifecycle models for the Seam application -->


      <phase-listener>org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener</phase-listener>
      <!-- phase-listener>org.jboss.seam.jsf.SeamPhaseListener</phase-listener -->


      </faces-config>
      ===

      Web.xml is:

      ===
      <?xml version="1.0" encoding="UTF-8"?>

      <web-app version="2.4"
      xmlns="http://java.sun.com/xml/ns/j2ee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

      <!-- Seam -->


      <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>


      <!-- Propagate conversations across redirects -->

      <filter-name>Seam Redirect Filter</filter-name>
      <filter-class>org.jboss.seam.servlet.SeamRedirectFilter</filter-class>


      <filter-mapping>
      <filter-name>Seam Redirect Filter</filter-name>
      <url-pattern>*.seam</url-pattern>
      </filter-mapping>


      <filter-name>Seam Exception Filter</filter-name>
      <filter-class>org.jboss.seam.servlet.SeamExceptionFilter</filter-class>


      <filter-mapping>
      <filter-name>Seam Exception Filter</filter-name>
      <url-pattern>*.seam</url-pattern>
      </filter-mapping>

      <!-- JSF -->

      <context-param>
      <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
      <param-value>client</param-value>
      </context-param>

      <context-param>
      <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
      <param-value>.xhtml</param-value>
      </context-param>

      <context-param>
      <param-name>facelets.DEVELOPMENT</param-name>
      <param-value>true</param-value>
      </context-param>


      <servlet-name>Faces Servlet</servlet-name>
      <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
      <load-on-startup>1</load-on-startup>


      <!-- Faces Servlet Mapping -->
      <servlet-mapping>
      <servlet-name>Faces Servlet</servlet-name>
      <url-pattern>*.seam</url-pattern>
      </servlet-mapping>

      <!-- MyFaces -->

      <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>


      <!-- JSF RI -->
      <!--

      <listener-class>com.sun.faces.config.ConfigureListener</listener-class>

      -->

      <context-param>
      <param-name>facelets.LIBRARIES</param-name>
      <param-value>/WEB-INF/tomahawk.taglib.xml</param-value>
      </context-param>



      <filter-name>MyFacesExtensionsFilter</filter-name>
      <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
      <init-param>
      <param-name>maxFileSize</param-name>
      <param-value>20m</param-value>
      </init-param>


      <!-- extension mapping for adding , , and other resource tags to JSF-pages -->
      <filter-mapping>
      <filter-name>MyFacesExtensionsFilter</filter-name>
      <!-- servlet-name must match the name of your javax.faces.webapp.FacesServlet entry -->
      <servlet-name>Faces Servlet</servlet-name>
      </filter-mapping>

      <!-- extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.) -->
      <filter-mapping>
      <filter-name>MyFacesExtensionsFilter</filter-name>
      <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
      </filter-mapping>

      <!-- filter-mapping>
      <filter-name>MyFacesExtensionsFilter</filter-name>
      <url-pattern>*.seam</url-pattern>
      </filter-mapping -->

      </web-app>

      ===