Recursive Entity causes strange behavior with EntityHome Id when trying to add child Entities
luxspes Sep 24, 2008 7:21 AMHi!
Here is a description of my problem:
Create a Seam 2 project using JBossTools, create an @Entity with a recursive relationship (lets name it Category).
@Entity public class Category { public Category() { } private Integer id; private String name; private Category parentCategory; private Set<Category>childrenCategories = new HashSet<Category>(); @Id @GeneratedValue(strategy=GenerationType.AUTO) public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } @ManyToOne public Category getParentCategory() { return parentCategory; } public void setParentCategory(Category parentCategory) { this.parentCategory = parentCategory; } @OneToMany(mappedBy="parentCategory") public Set<Category> getChildrenCategories() { return childrenCategories; } public void setChildrenCategories(Set<Category> childrenCategories) { this.childrenCategories = childrenCategories; } }
Then run Seam Generate Entities, run the application and create a category using the generated UI, save it with name category 1
and edit it.
If in Category.xhtml you click Add category
, instead of presenting a clean form for adding the new children, it will present a form with currently selected category: category 1
).
This is a bug, but it is not the one I am reporting here, but lets say you decide you want to fix it, and for starters you change the code in the Add category button to this:
<s:button value="Add category" view="/CategoryEdit.xhtml"> <f:param name="categoryId" value=""/> <f:param name="categoryFrom" value="Category"/> </s:button>
Note that the value for the categoryId is now empty (it used to have the #{categoryHome.instance.id} value). After making that change you run the application again and:
Edit category1
in Category.xhtml you click Add category
and you get what you would expect, an empty form to add the child category (of course many more changes are needed to make it possible to really add a child category, but that is not the issue here)
Now for the real bug:Lets say you are in a experimentative mood
and you decide to play with conversations, so, in layout/menu.xhtml you have a link to the CategoryList that looks like this:
<s:link view="/CategoryList.xhtml" value="Category List" propagation="none"/>
well, lets say you decide to add another one (just for the sake of experimenting) that looks like this:
<s:link view="/CategoryList.xhtml" value="Category List Propagation Begin" propagation="begin"/>
And then you Edit category1
in Category.xhtml you click Add category
and.... here comes the bug... the form is not empty, the <f:param name="categoryId" value=""/> plain just gets ignored.
Why? I think it that the fact that now everything is running inside a long running conversation shouldn't screw up things like this... Am I wrong?
Thanks,
Regards,