2 Replies Latest reply on Sep 1, 2008 3:34 AM by Alexandre Pelliccione

    Seam CRUD Application generated by Seam-gen

    Alexandre Pelliccione Newbie

      Hi all,


      I’m studying the seam framework and I came across a problem in the CRUD application generated by the seam-gen that is used as a data entry of two tables as follows:


      A ServiceOrder has one or more OrderItems.


      So, in order to create an OrderItem I need to select an existing ServiceOrder first according to the generated template through the “Select ServiceOrder” button.


      This action takes me to the ServiceOrderList page where I can select one of them.


      When I get back to the OrderItemEdit page all of the previous filled in fields lose their information, except the selected ServiceOrder.


      I’ve tried to check the generated code, xml files and the conversation parameters where it seems ok.


      I haven’t modified any code.


      I would like to know if any of you have experienced this problem or have some information in order to fix it.


      Thanks in advance.


        • 2. Re: Seam CRUD Application generated by Seam-gen
          Alexandre Pelliccione Newbie
          Hi Samuel.

          Thanks for your help.

          This is the code of the entity OrderItems:

          package org.domain.OrderEntry.entity;

          // Generated 28/08/2008 10:46:25 by Hibernate Tools 3.2.2.GA

          import javax.persistence.Column;
          import javax.persistence.Entity;
          import javax.persistence.FetchType;
          import javax.persistence.GeneratedValue;
          import static javax.persistence.GenerationType.IDENTITY;
          import javax.persistence.Id;
          import javax.persistence.JoinColumn;
          import javax.persistence.ManyToOne;
          import javax.persistence.Table;
          import org.hibernate.validator.Length;
          import org.hibernate.validator.NotNull;

          /**
          * Orderitem generated by hbm2java
          */
          @Entity
          @Table(name = "orderitem", catalog = "test")
          public class Orderitem implements java.io.Serializable {

                  private Integer orderItemId;
                  private Serviceorder serviceorder;
                  private String itemDescription;

                  public Orderitem() {
                  }

                  public Orderitem(Serviceorder serviceorder, String itemDescription) {
                          this.serviceorder = serviceorder;
                          this.itemDescription = itemDescription;
                  }

                  @Id
                  @GeneratedValue(strategy = IDENTITY)
                  @Column(name = "OrderItemID", unique = true, nullable = false)
                  public Integer getOrderItemId() {
                          return this.orderItemId;
                  }

                  public void setOrderItemId(Integer orderItemId) {
                          this.orderItemId = orderItemId;
                  }

                  @ManyToOne(fetch = FetchType.LAZY)
                  @JoinColumn(name = "OrderID", nullable = false)
                  @NotNull
                  public Serviceorder getServiceorder() {
                          return this.serviceorder;
                  }

                  public void setServiceorder(Serviceorder serviceorder) {
                          this.serviceorder = serviceorder;
                  }

                  @Column(name = "ItemDescription", nullable = false, length = 45)
                  @NotNull
                  @Length(max = 45)
                  public String getItemDescription() {
                          return this.itemDescription;
                  }

                  public void setItemDescription(String itemDescription) {
                          this.itemDescription = itemDescription;
                  }

          }

          and this is the code of the OrderItemHome:

          package org.domain.OrderEntry.session;

          import org.domain.OrderEntry.entity.*;
          import org.jboss.seam.annotations.In;
          import org.jboss.seam.annotations.Name;
          import org.jboss.seam.framework.EntityHome;

          @Name("orderitemHome")
          public class OrderitemHome extends EntityHome<Orderitem> {

                  @In(create = true)
                  ServiceorderHome serviceorderHome;

                  public void setOrderitemOrderItemId(Integer id) {
                          setId(id);
                  }

                  public Integer getOrderitemOrderItemId() {
                          return (Integer) getId();
                  }

                  @Override
                  protected Orderitem createInstance() {
                          Orderitem orderitem = new Orderitem();
                          return orderitem;
                  }

                  public void wire() {
                          getInstance();
                          Serviceorder serviceorder = serviceorderHome.getDefinedInstance();
                          if (serviceorder != null) {
                                  getInstance().setServiceorder(serviceorder);
                          }
                  }

                  public boolean isWired() {
                          if (getInstance().getServiceorder() == null)
                                  return false;
                          return true;
                  }

                  public Orderitem getDefinedInstance() {
                          return isIdDefined() ? getInstance() : null;
                  }

          }


          The page.xml for the OrderItemEdit.xhtml is:

          <?xml version="1.0" encoding="UTF-8"?>
          <page xmlns="http://jboss.com/products/seam/pages"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.0.xsd"
                no-conversation-view-id="/OrderitemList.xhtml"
                login-required="true">
            
             <begin-conversation join="true"/>
            
             <action execute="#{orderitemHome.wire}"/>
            
             <param name="orderitemFrom"/>
             <param name="orderitemOrderItemId" value="#{orderitemHome.orderitemOrderItemId}"/>
             <param name="serviceorderFrom"/>
             <param name="serviceorderOrderId" value="#{serviceorderHome.serviceorderOrderId}"/>



             <navigation from-action="#{orderitemHome.persist}">
                 <end-conversation/>
                 <redirect view-id="/Orderitem.xhtml"/>
             </navigation>
            
             <navigation from-action="#{orderitemHome.update}">
                 <end-conversation/>
                 <redirect view-id="/Orderitem.xhtml"/>
             </navigation>
            
             <navigation from-action="#{orderitemHome.remove}">
                 <end-conversation/>
                 <redirect view-id="/OrderitemList.xhtml"/>
             </navigation>
            
          </page>


          All of the above codes was generated by the seam-gen using Eclipse Seam-web project.

          Regards
          Alex