Simple Seam Question...
edwar64896 Mar 6, 2006 8:01 PMHi.
I am a newbie at Seam so please forgive what might seem to be an obvious question...
I'm trying to implement some hierarchy navigation screens. Code is posted below:
home.xhtml
...
<div class="chierarchy">
<h:dataTable value="#{categories}" var="cat">
<h:column>
<h:commandLink value="#{cat.name}" action="#{catList.select}" />
</h:column>
</h:dataTable>
</div>
...
CategoryListBean.java
...
@Stateful
@Scope(SESSION)
@Name("catList")
@Interceptors(SeamInterceptor.class)
public class CategoryListBean implements java.io.Serializable, CategoryList {
@DataModel
private List<Category> categories;
@Out(required=false)
@DataModelSelection
private Category category;
@PersistenceContext(type=EXTENDED)
private EntityManager em;
@Factory("categories")
public void findCategoryList() {
long catId=1;
try {
catId=category.getCategoryId();
} catch (Exception e) {}
System.out.println(catId);
categories = em.createQuery("from Category where parent_id = :parid")
.setParameter("parid",catId)
.getResultList();
}
public String select() {
return "selected";
}
public String delete() {
return "deleted";
}
@Remove @Destroy
public void destroy () {}
}
...
Category.java
...
@Entity
@Name("category")
public class Category implements java.io.Serializable {
private long categoryId;
private Collection<Asset> asset;
private Collection<Category> children;
private Category parent;
private String name;
public Category() {}
...
/**
* Get children.
*
* @return children as String.
*/
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="parent")
public Collection<Category> getChildren()
{
return children;
}
...
When a dataTable entry is selected in the browser, I am assuming that the selected "Category" will be passed in as the @DataModelSelection attribute and that the next time the table is rendered, the parent cateory will have changed. Unfortunately, this doesn't happen. I don't seem to get the expected behaviour and the page re-renders as before. Seeing as this is such a trivial problem, I would be grateful if someone could set me straight here.
Thanks.
Mark