[jboss-user] [JBoss Seam] - Need some clarification about seam-gen-ed EntityHome class

kingcu do-not-reply at jboss.com
Mon May 21 16:11:17 EDT 2007


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;
  | 	}
  | 
  | }
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4047364#4047364

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4047364



More information about the jboss-user mailing list