Question

I am new with Primefaces and I try to use a treeTable from Primefaces 3.3.1. Only the first record of the TreeTable is shown at the beginning. Then, when I click on the little image to expand the TreeTable, nothing happens. In FireBug, I can se the following result:

<partial-response>
    <error>
        <error-name>class java.lang.StringIndexOutOfBoundException</error-name>
        <error-message>String index out of range: -1</error-message>
    </error>
</partial-response>

If I force my treeTable to be expanded with node0.setExpanded(true), then the TreeTable is expanded. Then I can collapse it but again, I am no more able to expand it. In other posts, it is written that the model and/or the bean must implements Serializable. I try but it does not work.

Below, my model (what will be placed in each record of the TreeTable):

public class MyModel{
    private String field_1;
    private String field_2;
    public MyModel(){};
    public MyModel(String field_1, String field_2){
        this.field_1 = field_1;
        this.field_2 = field_2;
    }
    //Getters and setters
}    

Below, the JSF Managed bean that create the TreeTable:

@ManagedBean
@SessionScoped
public class MyManagedBean{
    public TreeNode root;
}
public MyManagedBean{
    root = new DefaultTreeNode("root",null);
    TreeNode node0 = new DefaultTreeNode(new MyModel("Field 1", "Field 2"), root);
    TreeNode sub0 = new DefaultTreeNode(new MyModel("Sub", "Sub"), node0);
    //node0.setExpanded(true);
}
public TreeNode getRoot(){
    return root;
}

Finally, my JSF file:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"     "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
    <f:view contentType="text/html">
        <h:head>
            <f:facet name="first">
                <meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
                <title>PrimeFaces</title>
            </f:facet>
        </h:head>
        <h:body>
            <p:treeTable value="#{myManagedBean.root}" var="test">    
            <p:column>
                <f:facet name="header">
                    Field 1
                </f:facet>
                <h:outputText value="#{test.field_1}" />
            </p:column>
            <p:column>
                <f:facet name="header">
                    Field 2
                </f:facet>
                <h:outputText value="#{test.field_2}" />
            </p:column>
        </p:treeTable>
    </h:body>
</f:view>

Thank you in advance for your help!

Was it helpful?

Solution

Solved it. I forgot to wrap the treeTable in an h:form tag. It works fine now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top