rich:tree shrinking all the time
katjuska Apr 8, 2010 6:18 AMHi,
I have a jsf-project which in I'm using rich:tree as a menu in the left side of the page.
I am using Apache Tomcat 6.0, jre 1.6.0, mojarra 1.2, RichFaces 3.3.0.
My problem is that the tree is shrinking all the time. Every time I click a link in the menutree and open a new page to the right side of the page, the whole tree is shrinking.
I am also using same kind of tree in my program and it is working just fine. The only difference I can think of is that this menu tree in the left side of the page is allways opening a new page. The other menu tree is reloading the same page with different parameters.
This is the link2open-funktion from the working menu:
public void link2open() throws DAOException { setCls(getNodeTitle()); FacesContext fc = FacesContext.getCurrentInstance(); HttpSession session = (HttpSession) fc.getExternalContext().getSession(false); session.setAttribute("product", classDAO.getProductNameByClass(cls)); setShowEditView(true); setEditMode(false); //System.out.println("Class to open: " + nodeTitle.getCLS_NAME()); } public String link2open() { String toRet = "open_errorpage"; if (tree.isRowAvailable()) {nodeTitle = (Menutree)tree.getRowData(); } setMenutree(getNodeTitle()); // In here I am checking the correct page to be opened from the tree-information in this form "open_newpage" toRet = "open_newpage"; //System.out.println("toRet: " + toRet); return toRet; }
This is my tree2nav.xhtml:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:rich="http://richfaces.org/rich"> <ui:composition> <h:form id="globaltreeForm"> <h:panelGrid columns="2" width="100%" columnClasses="col1,col2"> <rich:tree style="width:100px" nodeSelectListener="#{treeBacker.processSelection}" ajaxSubmitSelection="true" switchType="client" value="#{treeBacker.menuTree}" var="item" id="globaltree" treeNodeVar="rootNode" ajaxKeys="#{null}" nodeFace="leaf"> <rich:treeNode type="leaf" icon="/images/iconLeaf_gif.gif"> <h:commandLink actionListener="#{treeBacker.processAction}" value="#{item.MTR_LABEL}" immediate="true" action="#{treeBacker.link2open}" /> </rich:treeNode> </rich:tree> </h:panelGrid> </h:form> </ui:composition> </html> This is what I have in treeBacker.java: /** package myController; import java.util.ArrayList; import javax.faces.component.UIComponent; import misuDao.DAOException; import org.richfaces.component.html.HtmlTree; myController.UserRights UserRights = new myController.UserRights(); private Menutree nodeTitle; private void loadMenuTree() { public void processAction(ActionEvent event) throws AbortProcessingException { /** if (menutree.getPRO_ID().getValue() != 0L) { if (menutree.getRIG_ID().getValue() != 0L) { HttpSession session = (HttpSession) FacesContext.getCurrentInstance() public String getValue() { public void setValue(int valor) { public TreeNode<Menutree> getMenuTree() { public Menutree getNodeTitle() { public void setNodeTitle(Menutree nodeTitle) { public void setListType(Long listType) { public Long getListType() { public Menutree getMenutree() { public void setMenutree(Menutree menutree) { public void setTree(HtmlTree tree) { public HtmlTree getTree() { public void setProjectPageType(String projectPageType) { public String getProjectPageType() { } I would really appreciate any help, any new ideas what might be causing the problem. Thanks, Katja
* License Agreement. JBoss RichFaces - Ajax4jsf Component Library Copyright (C)
* 2007 Exadel, Inc. This library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation. This library is
* distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details. You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.servlet.http.HttpSession;
import myPackage.Menutree;
import org.richfaces.event.NodeSelectedEvent;
import org.richfaces.model.TreeNode;
import org.richfaces.model.TreeNodeImpl;
public class TreeBacker extends AbstractTreeBackerForm {
public static final String versionNo = "0.1";
private String value = null;
private TreeNode<Menutree> rootNode = null;
//private List<String> selectedNodeChildren = new ArrayList<String>();
private List<Menutree> selectedNodeChildren = new ArrayList<Menutree>();
ArrayList<String> treefolders;
private Menutree menutree = new Menutree();
private HtmlTree tree = new HtmlTree();
private Long listType;
private String projectPageType;
private void addNodes(String path, TreeNode<Menutree> node, TreeMap<String, Menutree> tr) {
boolean end = false;
int counter = 1;
while (!end) {
String key = path != null ? path + '.' + counter : String.valueOf(counter);
Menutree value = tr.get(key);
if (value != null) {
System.out.println("Key:" + key + " - Name: " + value.getMTR_LABEL());
TreeNodeImpl<Menutree> nodeImpl = new TreeNodeImpl<Menutree>();
nodeImpl.setData(value);
node.addChild(new Integer(counter), nodeImpl);
addNodes(key, nodeImpl, tr);
counter++;
} else {
end = true;
}
}
}
rootNode = new TreeNodeImpl<Menutree>();
addNodes(null, rootNode, menutreeDAO.createNewInstanceOfKey());
}
public void processSelection(NodeSelectedEvent event) {
HtmlTree tree = (HtmlTree) event.getComponent();
nodeTitle = (Menutree) tree.getRowData();
selectedNodeChildren.clear();
TreeNode<Menutree> currentNode = tree.getModelTreeNode(tree.getRowKey());
if (currentNode.isLeaf()) {
selectedNodeChildren.add(currentNode.getData());
} else {
Iterator<Map.Entry<Object, TreeNode<Menutree>>> it = currentNode.getChildren();
while (it != null && it.hasNext()) {
Map.Entry<Object, TreeNode<Menutree>> entry = it.next();
selectedNodeChildren.add(entry.getValue().getData());
System.out.println(entry.getValue().getData().getMTR_LABEL().getValue());
}
}
}
UIComponent component = (UIComponent) event.getSource();
while (!(component != null && component instanceof HtmlTree)) {
component = component.getParent();
}
if (component != null) {
HtmlTree tree = (HtmlTree) component;
nodeTitle = (Menutree) tree.getRowData();
System.out.println("nodeTitle:"+nodeTitle.getMTR_LABEL().getValue());
}
}
* Defains which page will be opened when clicked from the tree menu
*
* @return toRet is the navigation string for faces-config.xml
*/
public String link2open() {
String toRet = "open_errorpage";
if (tree.isRowAvailable()) {
nodeTitle = (Menutree)tree.getRowData();
}
setMenutree(getNodeTitle());
// Set current, selected projectId to session
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
session.setAttribute("projectid", menutree.getPRO_ID().getValue());
try {
session.setAttribute("projectname", userDAO.getNameOfProject(menutree.getPRO_ID().getValue()));
session.setAttribute("product", userDAO.getProductOfProject(menutree.getPRO_ID().getValue()));
session.setAttribute("subprojects", userDAO.getSubProjects(menutree.getPRO_ID().getValue()));
System.out.println("SESSION PROJECTINFO:"+session.getAttribute("projectid")+":"+session.getAttribute("projectname")+":"+session.getAttribute("subprojects"));
} catch (DAOException e) {
e.printStackTrace();
}
}
boolean right = false;
if (menutree.getPRO_ID().getValue() != 0L) {
right = UserRights.CheckIfUserHasRight(menutree.getRIG_ID().getValue(), myController.UserRights.RIGHT_TYPE_VIEW);
} else {
right = UserRights.CheckIfUserHasRight(menutree.getRIG_ID().getValue(), myController.UserRights.RIGHT_TYPE_VIEW, 0L, true);
}
if (right) {
if (menutree.getJTG_COMMAND().getValue() != null && !menutree.getJTG_COMMAND().getValue().equals("")) {
toRet = menutree.getJTG_COMMAND().getValue();
} else {
toRet = "open_errorpage";
}
} else {
toRet = "open_norightpage";
}
} else {
}
return toRet;
}
public String goTo(String ret) {
.getExternalContext().getSession(false);
session.setAttribute("pagetoopen", ret);
return ret;
}
return value;
}
this.value = treefolders.get(valor);
System.out.println("this.value: " + this.value);
}
if (rootNode == null) {
loadMenuTree();
}
return rootNode;
}
return nodeTitle;
}
this.nodeTitle = nodeTitle;
}
this.listType = listType;
}
return listType;
}
return menutree;
}
this.menutree = menutree;
}
public HashMap<String,String> getArguments(String arguments) {
HashMap<String,String> arg = new HashMap<String,String>();
try {
if (arguments != null && !arguments.equals("")) {
String[] values = arguments.split(";");
if (values.length > 0) {
for (int i=0; i<values.length; i++) {
String[] temp = values[i].split("=");
if (temp.length > 1) {
arg.put(temp[0], temp[1]);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return arg;
}
this.tree = tree;
}
return tree;
}
this.projectPageType = projectPageType;
}
return projectPageType;
}