[jboss-user] [Beginners Corner] - richfaces richTree can't get item.type!

FTEngine do-not-reply at jboss.com
Wed Feb 6 10:26:39 EST 2008


Hi there,

i'm new to richfaces and i'm testing the richtree component. I have a problem with nodeFace!!

I understand that it maps the current Tree Node with the type attribute of the possible treeNode tags. But somehow I cannot access it dynamically. If I type: nodeFace="foo" and <rich:treeNode type="foo"> my tree woks completely fine. But if try nodeFace="{item.type}" or nodeFace="#{item.type}" it does not work (I also tried nodeFace="#{item.class.name}"). My tree builds up fine but then I cant access my action="#{organisationseinheitTreeController.selectOrganisationseinheit}". 

I can tell form the sound of my browser that the link has not been activated. It is dead. When I debug my program, organisationseinheitTreeController.selectOrganisationseinheit is not been entered. 

I read somewhere that item represents a bean form my data model, which is nested in the treeNode. Thats why I build OrganisationseinheitTreeItem (By the way Organisationseinheit is German and stands for unit). I listed my JSF JSP, BackingBean and OrganisationseinheitTreeItem below.

Whats worng? 


  | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  |     pageEncoding="ISO-8859-1"%>
  | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  | <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
  | <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
  | <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
  | <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
  | <html>
  | <head>
  | 	<link rel="stylesheet" type="text/css"  href="<%= request.getContextPath() %>/prozessmanager/stylesheets/basic.css"  />
  | 	
  | 	<title>OrganisationseinheitTree</title>
  | 	</head>
  | 	<body>
  | 	<f:view>
  | 		<h:form>
  | 			<
  | 			rich:tree style="width:300px"
  | 			nodeSelectListener="#organisationseinheitTreeController.selectOrganisationseinheitListener}"
  | 			reRender="selectedNode" ajaxSubmitSelection="false"
  | 			var="item"
  | 			nodeFace="#{item.type}"
  | 			switchType="client" 
  | 			value="#{organisationseinheitTreeController.treeNode}" 
  | 			>
  | 				<rich:treeNode type="organisationseinheit">
  | 					<h:commandLink action="#{organisationseinheitTreeController.selectOrganisationseinheit}">
  | 						<h:outputText value="#{item}"/>	
  | 					</h:commandLink>
  | 				</rich:treeNode>
  | 					
  | 			</rich:tree>
  | 								
  | 				
  | 		</h:form>
  | 	</f:view>
  | 			
  | 	</body>
  | </html>
  | 

  | package prozessManager.controller.organisationseinheit;
  | 
  | import java.util.Iterator;
  | 
  | import org.richfaces.event.NodeSelectedEvent;
  | import org.richfaces.model.TreeNode;
  | import org.richfaces.model.TreeNodeImpl;
  | 
  | import prozessManager.controller.Controller;
  | import prozessManager.controller.Outcome;
  | import prozessManager.domain.organisationseinheit.Organisationseinheit;
  | import prozessManager.services.HibernateUtil;
  | import prozessManager.services.JSFService;
  | 
  | public class OrganisationseinheitTreeController extends Controller {
  | 	
  | 	private OrganisationseinheitTreeController dummy = this;
  | 	
  | 	private Outcome outcome = new OrganisationseinheitTreeOutcome("organisationseinheit") {
  | 		public void actionListener(Organisationseinheit organisationseinheit) {
  | 			OrganisationseinheitController organisationseinheitController = JSFService.getInstance().getOrganisationseinheitController();
  | 			organisationseinheitController.setOrganisationseinheit(organisationseinheit);
  | 			
  | 			organisationseinheitController.setPredecessor(dummy);
  | 			JSFService.getInstance().setController(organisationseinheitController);		
  | 		}	
  | 	};
  | 	
  | 	TreeNode rootTreeNode = null;
  | 	
  | 	private Organisationseinheit getRootOrganisationsEinheit() {
  | 		return (Organisationseinheit) HibernateUtil.getCurrentSession().createQuery("from Organisationseinheit where id = 1 order by name ").list().get(0);
  | 	}
  | 	
  | 	
  | 	public TreeNode getTreeNode() {
  | 		if (rootTreeNode == null)  {
  | 			rootTreeNode = new OrganisationseinheitNode(getRootOrganisationsEinheit());
  | 		}					
  | 		return rootTreeNode;
  | 	}
  | 	
  | 	public void selectOrganisationseinheitListener(NodeSelectedEvent event) {	
  | 		if (outcome != null) {
  | 			outcome.actionListener(event);
  | 		}
  | 		
  | 	}
  | 	
  | 	public String getViewName() {
  | 		return "organisationseinheitTree";
  | 	}
  | 
  | 
  | 	public Outcome getOutcome() {
  | 		return outcome;
  | 	}
  | 
  | 
  | 	public void setOutcome(Outcome outcome) {
  | 		this.outcome = outcome;
  | 	}	
  | 	
  | 	public String selectOrganisationseinheit() {
  | 		if (outcome != null) {		
  | 			return outcome.getOutcomeString();
  | 		}
  | 		else {
  | 			return null;
  | 		}
  | 	}
  | 	
  | 	public String selectMitarbeiter() {
  | 		if (outcome != null) {		
  | 			return outcome.getOutcomeString();
  | 		}
  | 		else {
  | 			return null;
  | 		}
  | 	}
  | 	
  | }
  | 

  | package prozessManager.controller.organisationseinheit;
  | 
  | import java.util.Iterator;
  | 
  | import org.richfaces.model.TreeNode;
  | import org.richfaces.model.TreeNodeImpl;
  | 
  | import prozessManager.controller.mitarbeiter.MitarbeiterNode;
  | import prozessManager.domain.mitarbeiter.Mitarbeiter;
  | import prozessManager.domain.organisationseinheit.Organisationseinheit;
  | 
  | public class OrganisationseinheitNode extends TreeNodeImpl{
  | 	private OrganisationseinheitTreeItem organisationseinheitTreeItem = new OrganisationseinheitTreeItem();
  | 	
  | 	
  | 
  | 	public OrganisationseinheitTreeItem getOrganisationseinheitTreeItem() {
  | 		return organisationseinheitTreeItem;
  | 	}
  | 	
  | 	public OrganisationseinheitNode(Organisationseinheit organisationseinheit) {
  | 		this.organisationseinheitTreeItem.setOrganisationseinheit(organisationseinheit) ;
  | 		initialize();
  | 		setData(organisationseinheit.getName());
  | 	}
  | 	
  | 	private boolean initialized = false;
  | 	
  | 	private static int counter = 1;
  | 	
  | 	private void initialize() {
  | 		if(!initialized) {
  | 			Organisationseinheit organisationseinheit = getOrganisationseinheitTreeItem().getOrganisationseinheit();
  | 			Iterator iterator = organisationseinheit.getMitarbeiterSet().iterator();
  | //			while(iterator.hasNext()) {
  | //				Mitarbeiter mitarbeiter = (Mitarbeiter) iterator.next();
  | //				TreeNode treeNode = new MitarbeiterNode(mitarbeiter);
  | //				addChild(counter++, treeNode);
  | //			}
  | 			iterator = organisationseinheit.getKindOrganisationseinheitList().iterator();
  | 			while(iterator.hasNext()) {
  | 				Organisationseinheit kindOrganisationseinheit = (Organisationseinheit) iterator.next();
  | 				TreeNode treeNode = new OrganisationseinheitNode(kindOrganisationseinheit );
  | 				addChild(counter++, treeNode);
  | 			}
  | 			initialized = true;
  | 		}
  | 	}
  | }

  | package prozessManager.controller.organisationseinheit;
  | 
  | import prozessManager.domain.organisationseinheit.Organisationseinheit;
  | 
  | public class OrganisationseinheitTreeItem {
  | 	public OrganisationseinheitTreeItem() {
  | 		
  | 	}
  | 	private Organisationseinheit organisationseinheit;
  | 	public OrganisationseinheitTreeItem(Organisationseinheit organisationseinheit) {
  | 		this.organisationseinheit = organisationseinheit;
  | 	}
  | 	public String getType(){
  | 		return "organisationseinheit";
  | 	}
  | 	public Organisationseinheit getOrganisationseinheit() {
  | 		return organisationseinheit;
  | 	}
  | 	public void setOrganisationseinheit(Organisationseinheit organisationseinheit) {
  | 		this.organisationseinheit = organisationseinheit;
  | 	}
  | 	
  | }
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4127042#4127042

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4127042



More information about the jboss-user mailing list