You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Dean Hiller <de...@xsoftware.biz> on 2006/04/12 15:49:39 UTC
hibernate and myfaces...newb design question
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.
Re: hibernate and myfaces...newb design question
Posted by Mike Kienenberger <mk...@gmail.com>.
On 4/12/06, Dean Hiller <de...@xsoftware.biz> wrote:
> 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?
Use a Converter. Typically you'd use the primary key as the
converted value representation, but you don't have to.