Cast exception using UITre/HtmlTree
leukipp Oct 15, 2007 5:20 PMWe took http://livedemo.exadel.com/richfaces-demo/richfaces/tree.jsf to as an template to implement a category tree. Everything worked well until we tried to access the selected node of the tree. First we run into the following error:
WARN [lifecycle] /admin/categories.xhtml @36,71 nodeSelectListener="#{categoryManager.processSelection}": javax.ejb.EJBTransactionRolledbackException: java.lang.NoClassDefFoundError: org/richfaces/component/UITreeSo we moved the libraries richfaces-*.jar into the classpath of JBoss. Afterwards we got the following error:
WARN [lifecycle] /admin/categories.xhtml @36,71 nodeSelectListener="#{categoryManager.processSelection}": javax.ejb.EJBTransactionRolledbackException: org.richfaces.component.html.HtmlTree cannot be cast to org.richfaces.component.UITreeNote, that HtmlTree is a subclass of UITree. We also tried using Java 1.5 and 1.6, and we upgraded Seam to 2.0.0CR2. However, we could solve our problem. Does anyone know a solution?
Here are some more information:
- We are using jboss-4.2.1.GA
The implementation goes as follows (xhtml and java files):
<h3>Gerade ausgewählt (AJAX-Tree)</h3>
<h:outputText escape="false"
value="Selected Node: #{categoryManager.treeCat}" id="selectedNode" />
<h3>Ajax-Tree</h3>
<h:form>
<rich:tree style="width:300px"
nodeSelectListener="#{categoryManager.processSelection}"
reRender="selectedNode" ajaxSubmitSelection="true"
switchType="ajax" value="#{categoryManager.treeNode}" var="item">
</rich:tree>
</h:form>
@Stateful
@Name("categoryManager")
public class CategoryManager implements ICategoryManager {
@DataModel
private List<Category> categoryList;
@DataModelSelection
@Out(required = false)
private Category selectedCategory;
@PersistenceContext(type = PersistenceContextType.EXTENDED)
private EntityManager em;
private TreeNode rootNode = null;
private Category treeCat = null;
@SuppressWarnings("unchecked")
@Factory("categoryList")
public void findCategories() {
categoryList = em.createQuery(
"from Category cat where cat.parent is null order by cat.name")
.getResultList();
}
@End
public void update() {
em.flush();
em.refresh(selectedCategory);
}
@Begin(join = true)
public void select() {
}
public void delete() {
categoryList.remove(selectedCategory);
em.remove(selectedCategory);
selectedCategory = null;
}
@Remove
public void destroy() {
}
private void addNodes(Category rootNode, TreeNode node,
List<Category> catList) {
int counter = 1;
for (Category cat : catList) {
if ((rootNode == null && cat.getParent() == null)
|| ((rootNode != null && cat.getParent() != null) && (cat
.getParent().equals(rootNode)))) {
TreeNodeImpl nodeImpl = new TreeNodeImpl();
nodeImpl.setData(cat);
node.addChild(new Integer(counter), nodeImpl);
// TODO: testen, ob's mit einkommentiertem Befehl eine
// concurrentModificationException gibt
// catList.remove(cat);
addNodes(cat, nodeImpl, catList);
counter++;
}
}
}
@SuppressWarnings("unchecked")
private void loadTree() {
rootNode = new TreeNodeImpl();
List<Category> objects = em.createQuery("from Category")
.getResultList();
addNodes(null, rootNode, objects);
}
public TreeNode getTreeNode() {
if (rootNode == null) {
loadTree();
}
return rootNode;
}
public void processSelection(NodeSelectedEvent event) {
UITree tree = (UITree)event.getComponent();
treeCat = (Category) tree.getRowData();
}
public Category getTreeCat() {
return treeCat;
}
public void setTreeCat(Category treeCat) {
this.treeCat = treeCat;
}
}