myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dirk Krummacker (JIRA)" <...@myfaces.apache.org>
Subject [jira] Created: (TRINIDAD-1103) tr:tree: nodes cannot be closed if initiallyExpanded=true
Date Fri, 30 May 2008 12:25:45 GMT
tr:tree: nodes cannot be closed if initiallyExpanded=true
---------------------------------------------------------

                 Key: TRINIDAD-1103
                 URL: https://issues.apache.org/jira/browse/TRINIDAD-1103
             Project: MyFaces Trinidad
          Issue Type: Bug
    Affects Versions:  1.0.8-core, 1.0.7-core
         Environment: Observed with Windows XP, IE6 or Firefox 2.0.0.14, Apache MyFaces Core
1.1.5 and Trinidad 1.0.7 and 1.0.8.
            Reporter: Dirk Krummacker
            Priority: Minor


The tr:tree and the tr:treetable component both have the attribute "initiallyExpanded" which
allows to open the whole tree on first rendering. While the tr:treeTable works exactly as
I would expect, the tr:tree shows some odd behavior: The tree is fully expanded, but any subsequent
click on a [-] collapse icon does not have any effect.

Test case:

1. Go to http://www.irian.at/trinidad-demo/faces/components/treeTable.jspx
2. Check "initiallyExpanded" and click "Update".
3. The tr:treeTable is expanded and you can close/open nodes.
4. And now go to http://www.irian.at/trinidad-demo/faces/components/tree.jspx
5. Check "initiallyExpanded" and click "Update".
6. The tr:tree is expanded, but the nodes cannot be collapsed.

----- tree.jsp -----

<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/trinidad" prefix="tr"%>
<%@ taglib uri="http://myfaces.apache.org/trinidad/html" prefix="trh"%>

<f:view>
	<trh:html>
	<trh:head title="Tree Initially Expanded" />

	<trh:body>
		<tr:form>
			<tr:tree var="node" value="#{treeModelBean.treeModel}"
				initiallyExpanded="true">
				<f:facet name="nodeStamp">
					<tr:outputText value="#{node.name}" />
				</f:facet>
			</tr:tree>
		</tr:form>
	</trh:body>
	</trh:html>
</f:view>

----- TreeModelBean.java -----

package test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.apache.myfaces.trinidad.context.RequestContext;
import org.apache.myfaces.trinidad.model.ChildPropertyTreeModel;
import org.apache.myfaces.trinidad.model.RowKeySet;
import org.apache.myfaces.trinidad.model.RowKeySetImpl;
import org.apache.myfaces.trinidad.model.TreeModel;

public class TreeModelBean
{
    public TreeModel getTreeModel()
    {
        List<Node> empty = Collections.emptyList();

        List<Node> fruits = new ArrayList<Node>();
        fruits.add(new Node("Bananas", empty));
        fruits.add(new Node("Apples", empty));
        fruits.add(new Node("Cherries", empty));

        List<Node> vegetables = new ArrayList<Node>();
        vegetables.add(new Node("Carrots", empty));
        vegetables.add(new Node("Potatoes", empty));
        vegetables.add(new Node("Salad", empty));

        List<Node> edibles = new ArrayList<Node>();
        edibles.add(new Node("Fruits", fruits));
        edibles.add(new Node("Vegetables", vegetables));

        List<Node> root = new ArrayList<Node>();
        root.add(new Node("Edibles", edibles));

        return new ChildPropertyTreeModel(root, "children");
    }

    public static class Node
    {
        public Node(String name, List<Node> children)
        {
            this.name = name;
            this.children = children;
        }

        public String getName()
        {
            return name;
        }

        public List<Node> getChildren()
        {
            return children;
        }

        private String name;
        private List<Node> children;
    }
}

----- End -----

Workaround 1: Use a tr:treeTable without columns instead of tr:tree.

Workaround 2: Don't use the attribute "initiallyExpanded" but open the nodes yourself on first
display. For this, bind the attribute "disclosedRowKeys" to the following method:

    public RowKeySet getDisclosedRowKeys()
    {
        RequestContext requestContext = RequestContext.getCurrentInstance();
        Map<String, Object> pageFlowScope = requestContext.getPageFlowScope();
        RowKeySet disclosedRowKeys = (RowKeySet) pageFlowScope.get("disclosedRowKeys");
        if (disclosedRowKeys == null)
        {
            disclosedRowKeys = new RowKeySetImpl();

            List<Integer> discloseRoot = Collections.singletonList(0);
            disclosedRowKeys.add(discloseRoot);

            List<Integer> discloseFruits = new ArrayList<Integer>();
            discloseFruits.add(0);
            discloseFruits.add(0);
            disclosedRowKeys.add(discloseFruits);

            List<Integer> discloseVegetables = new ArrayList<Integer>();
            discloseVegetables.add(0);
            discloseVegetables.add(1);

            disclosedRowKeys.add(discloseVegetables);
            pageFlowScope.put("disclosedRowKeys", disclosedRowKeys);
        }
        return disclosedRowKeys;
    }






-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message