I don't know if this is the best design, but I use the files
AddChildForm.java
ChildBean.java
ParentBean.java
My ChildBean and ParentBean are EJB3 objects(ie. hibernate if using that
implementation). AddChildForm has a pulldown which lists all the
parents and optionally a "none" in case it is a new root. I had the
following backing method on the f:selectItems tag....
public Map getAllParents() {
List<ParentBean> parents =
DatabaseFacade.getInstance().getAllParents();
releases.add(0, ParentBean.NULL_RELEASE);
Map<String, ParentBean> items = new HashMap<String, ParentBean>();
for(ParentBean parent : parents) {
items.put(parent.getName(), parent);
}
return items;
}
unfortunately, when JSF/MyFaces calls
AddChildForm.getChildBean().getParent(), that returns a ParentBean. I
think JSF wants a String so it knows which item in the list is currently
selected. It seems as if I can't just pass around objects. I am
thinking I may have to use the database id? Is there any cleaner way
than that? The method above would be quite clean as setParent() would
actually just set the ParentBean stored in the Map which would be nice.
Any ideas?
thanks,
dean
My form contains that bean.