6 Replies Latest reply on May 24, 2007 11:05 AM by Tong Wang

    Need some clarification about seam-gen-ed EntityHome class

    Tong Wang Newbie

      Hi,

      I used "seam generate-entities" to generate a complete CRUD application from an existing database schema. Everything works great! I just need some clarification/education to better understand EntityHome.

      Here is the background description: there is a bidirectional one-to-many relation between two entities, Widget (1) <---> Feed (n), entity Widget on the one side and entity Feed on the many side. Below are the seam generated classes extending EntityHome.

      So, my questions are:

      1. Why isWired() always returns true? In other words, is there any situation that this method needs to return false?

      2. wire() seems to be the method to "wire up" the correct entity relation, but it's empty in WidgetHome class, even though this is a bidirectional relation and both sides need to be wired, why?

      3. the wire() method is only referenced in page.xml as a page action (I can't find a complete description about page.xml anywhere, but I guess the purpose of action element is to call some method on page load, right?), the creation/refreshing of the home component seems unclear to me.

      Thanks.

      WidgetHome.java

      package com.kfi.was.entity;
      
      import java.math.BigDecimal;
      import java.util.ArrayList;
      import java.util.List;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.framework.EntityHome;
      
      @Name("widgetHome")
      public class WidgetHome extends EntityHome<Widget> {
      
       public void setWidgetId(BigDecimal id) {
       setId(id);
       }
      
       public BigDecimal getWidgetId() {
       return (BigDecimal) getId();
       }
      
       @Override
       protected Widget createInstance() {
       Widget widget = new Widget();
       return widget;
       }
      
       public void wire() {
       }
      
       public boolean isWired() {
       return true;
       }
      
       public Widget getDefinedInstance() {
       return isIdDefined() ? getInstance() : null;
       }
      
       public List<Feed> getFeeds() {
       return getInstance() == null ? null : new ArrayList<Feed>(getInstance()
       .getFeeds());
       }
      
      }
      


      FeedHome.java
      package com.kfi.was.entity;
      
      import java.math.BigDecimal;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.framework.EntityHome;
      
      @Name("feedHome")
      public class FeedHome extends EntityHome<Feed> {
      
       @In(create = true)
       WidgetHome widgetHome;
      
       public void setFeedId(BigDecimal id) {
       setId(id);
       }
      
       public BigDecimal getFeedId() {
       return (BigDecimal) getId();
       }
      
       @Override
       protected Feed createInstance() {
       Feed feed = new Feed();
       return feed;
       }
      
       public void wire() {
       Widget widget = widgetHome.getDefinedInstance();
       if (widget != null) {
       getInstance().setWidget(widget);
       }
       }
      
       public boolean isWired() {
       return true;
       }
      
       public Feed getDefinedInstance() {
       return isIdDefined() ? getInstance() : null;
       }
      
      }