0 Replies Latest reply on Nov 23, 2009 2:35 PM by daxxy

    Edit dataTable with modalPanel cannot save changes

    daxxy

      I am basing my code on the richfaces demo example "Edit Table with ModalPanel". I am using a seam-generated application, which differs slightly from the example.

      The view is this:

      <ui:define name="body">
      
       <div style="clear: both" />
       <h:form>
       <a4j:region>
       <rich:dataTable id="dataTable" value="#{devTagsList.resultList}"
       var="_devtags" ajaxKeys="#{assetTag.rowsToUpdate}" rowKeyVar="rowId">
       <rich:column>
       <f:facet name="header">Row ID</f:facet>
       <h:outputText value="#{rowId}" id="rowid" />
       </rich:column>
       <rich:column>
       <f:facet name="header">
       <h:outputText value="Asset Tag" />
       </f:facet>
       <h:outputText value="#{_devtags.devTagId}" id="hostname" />
       </rich:column>
       <rich:column>
       <f:facet name="header">
       <h:outputText value="Serial Number" />
       </f:facet>
       <h:outputText value="#{_devtags.devSerialNum}" id="platform" />
       </rich:column>
       <rich:column>
       <f:facet name="header">
       <h:outputText value="Comment" />
       </f:facet>
       <h:outputText value="#{_devtags.comment}" id="devId" />
       </rich:column>
       <rich:column>
       <f:facet name="header">
       <h:outputText value="Tag ID" />
       </f:facet>
       <h:outputText value="#{_devtags.tagId}" id="tagId" />
       </rich:column>
       <rich:column>
       <f:facet name="header">
       <h:outputText value="Device Id" />
       </f:facet>
       <h:outputText value="#{_devtags.devId}" />
       </rich:column>
       <rich:column>
       <a4j:commandLink ajaxSingle="true" id="editLink"
       oncomplete="#{rich:component('editPanel')}.show()" >
       <h:graphicImage value="/img/icons/edit.gif" style="border:0" />
       <f:setPropertyActionListener value="#{_devtags}"
       target="#{devTagsHome.instance}" />
       </a4j:commandLink>
       </rich:column>
       </rich:dataTable>
       <rich:messages style="color:red;"></rich:messages>
       </a4j:region>
      </h:form>
       <rich:modalPanel id="editPanel" autosized="true" width="450">
       <f:facet name="header">Asset Tag</f:facet>
       <f:facet name="controls">
       <h:panelGroup>
       <h:graphicImage value="/img/modal/close.png"
       id="hideEditPanel" styleClass="hidelink"
       onclick="#{rich:component('editPanel')}.hide()" />
       </h:panelGroup>
       </f:facet>
       <h:form>
       <rich:messages for="assetTagPanel" style="color:red;"></rich:messages>
       <a4j:outputPanel ajaxRendered="true" id="assetTagPanel">
       <h:panelGrid columns="2">
       <h:outputText value="Serial Number. Change if necessary" />
       <h:inputText value="#{devTagsHome.instance.devSerialNum}" />
       <h:outputText value="Asset Tag" />
       <h:inputText value="#{devTagsHome.instance.devTagId}" />
       <h:outputText value="Comment" />
       <h:inputText value="#{devTagsHome.instance.comment}" />
       <h:outputText value="Instance ID" />
       <h:outputText value="#{devTagsHome.id}" />
       </h:panelGrid>
       <a4j:commandButton value="Update"
       action="#{devTagsHome.update(devTagsHome.instance.tagId)}"
       oncomplete="#{rich:component('editPanel')}.hide()"
       reRender="dataTable" />
       </a4j:outputPanel>
       </h:form>
       </rich:modalPanel>
       </ui:define>
      


      Here is DevTags.java:

      @Entity
      @Table(name = "dev_tags")
      @AutoCreate
      @Name("devTags")
      public class DevTags implements java.io.Serializable {
      
       private Integer tagId;
       private String devTagId;
       private String devSerialNum;
       private String comment;
       private String singleSiteCode;
       private Integer devId;
      
       public DevTags() {
       }
      
       public DevTags(Integer devId, String devSerialNum) {
       this.devSerialNum = devSerialNum;
       this.devId = devId;
       }
      
      
       @Id
       @GeneratedValue(strategy = IDENTITY)
       @Column(name = "tag_id", unique = true, nullable = false)
       public Integer getTagId() {
       return this.tagId;
       }
      
       public void setTagId(Integer tagId) {
       this.tagId = tagId;
       }
      
       @Column(name = "dev_tag_id", length = 45)
       @Length(max = 45)
       public String getDevTagId() {
       return this.devTagId;
       }
      
       public void setDevTagId(String devTagId) {
       this.devTagId = devTagId;
       }
      
       @Column(name = "dev_serial_num_hard", length = 45)
       @Length(max = 45)
       public String getDevSerialNum() {
       return this.devSerialNum;
       }
      
       public void setDevSerialNum(String devSerialNum) {
       this.devSerialNum = devSerialNum;
       }
      
       @Column(name = "comment", length = 65535)
       @Length(max = 65535)
       public String getComment() {
       return this.comment;
       }
      
       public void setComment(String comment) {
       this.comment = comment;
       }
      
       @Transient
       public String getSingleSiteCode() {
       return this.singleSiteCode;
       }
      
      
       public void setSingleSiteCode(String singleSiteCode) {
       this.singleSiteCode = singleSiteCode;
       }
      
       @Column(name = "dev_id")
       public Integer getDevId() {
       return this.devId;
       }
      
       public void setDevId(Integer devId) {
       this.devId = devId;
       }
      
      
      }



      And DevTagsHome.java:

      package dne.nib.assettags.action;
      
      import java.util.Set;
      
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.framework.EntityHome;
      
      import dne.nib.assettags.model.DevTags;
      
      @Name("devTagsHome")
      public class DevTagsHome extends EntityHome<DevTags> {
      
      
       public void setDevTagsTagId(Integer id) {
       setId(id);
       }
      
       public Integer getDevTagsTagId() {
       return (Integer) getId();
       }
      
       @Override
       protected DevTags createInstance() {
       DevTags devTags = new DevTags();
       return devTags;
       }
      
       public void load() {
       if (isIdDefined()) {
       wire();
       }
       }
       public void wire() {
       getInstance();
       }
      
       public boolean isWired() {
       return true;
       }
      
       public DevTags getDefinedInstance() {
       return isIdDefined() ? getInstance() : null;
       }
      
      
       public String update(Integer id) {
       System.out.println("instance id defined "+isIdDefined());
       System.out.println("instance id "+ id);
       System.out.println("isManaged = "+this.isManaged());
       return super.update();
       }
      
      }



      When I click on the Edit button to bring up the ModalPanel it works fine. All fields are populated. When I try to update the instance using DevTagsHome.update(), I get this output on the console:

      14:28:42,028 INFO [STDOUT] Hibernate:
       select
       devtags0_.tag_id as tag1_33_,
       devtags0_.comment as comment33_,
       devtags0_.dev_id as dev3_33_,
       devtags0_.dev_serial_num_hard as dev4_33_,
       devtags0_.dev_tag_id as dev5_33_
       from
       ond.dev_tags devtags0_ limit ?
      14:28:46,372 INFO [STDOUT] instance id defined false
      14:28:46,372 INFO [STDOUT] instance id 0
      14:28:46,372 INFO [STDOUT] isManaged = false
      14:28:46,513 INFO [STDOUT] Hibernate:
       select
       devtags0_.tag_id as tag1_33_,
       devtags0_.comment as comment33_,
       devtags0_.dev_id as dev3_33_,
       devtags0_.dev_serial_num_hard as dev4_33_,
       devtags0_.dev_tag_id as dev5_33_
       from
       ond.dev_tags devtags0_ limit ?



      To me, my code seems pretty much identical to the example on the richfaces demo. My devTagsHome is analogous to DataScrollerBean. My instance is the currentItem and my update() is the same as store().

      And yet, when I click on update(), the app acts like it has never seen my devTags instance before?

      This is driving me crazy. Can someone help?