TreeTable - Edit

Data displayed on treetable can be edited at row or cell level.

Row Editing
NameSizeType
Cell Editing
NameSizeType
<style type="text/css">
    .ui-row-editor .ui-row-editor-pencil {
        margin-left:8px;
    }

    .ui-editable-column .ui-cell-editor-input {
        overflow: hidden;
    }

    .ui-editable-column .ui-cell-editor-input * {
        box-sizing: border-box;
    }
</style>


 <h:form id="form">
    <p:growl id="msgs" showDetail="true"/>

    <p:treeTable value="#{ttEditView.root}" editable="true" var="document" style="margin-bottom:20px">
        <f:facet name="header">
            Row Editing
        </f:facet>
        
        <p:ajax event="rowEdit" listener="#{ttEditView.onRowEdit}" update=":form:msgs" />
        <p:ajax event="rowEditCancel" listener="#{ttEditView.onRowCancel}" update=":form:msgs" />

        <p:column headerText="Name"> 
            <p:cellEditor>
                <f:facet name="output"><h:outputText value="#{document.name}" /></f:facet>
                <f:facet name="input"><p:inputText value="#{document.name}" style="width:100%"/></f:facet>
            </p:cellEditor>
        </p:column>
        <p:column headerText="Size">
            <p:cellEditor>
                <f:facet name="output"><h:outputText value="#{document.size}" /></f:facet>
                <f:facet name="input"><p:inputText value="#{document.size}" style="width:100%"/></f:facet>
            </p:cellEditor>
        </p:column>
        <p:column headerText="Type">
            <p:cellEditor>
                <f:facet name="output"><h:outputText value="#{document.type}" /></f:facet>
                <f:facet name="input"><p:inputText value="#{document.type}" style="width:100%"/></f:facet>
            </p:cellEditor>
        </p:column>
        <p:column style="width:32px">
            <p:rowEditor />
        </p:column>
    </p:treeTable>

    <p:treeTable value="#{ttEditView.root2}" editable="true" editMode="cell" var="document">
        <f:facet name="header">
            Cell Editing
        </f:facet>
        
        <p:ajax event="cellEdit" listener="#{ttEditView.onCellEdit}" update=":form:msgs" />

        <p:column headerText="Name"> 
            <p:cellEditor>
                <f:facet name="output"><h:outputText value="#{document.name}" /></f:facet>
                <f:facet name="input"><p:inputText value="#{document.name}" style="width:100%"/></f:facet>
            </p:cellEditor>
        </p:column>
        <p:column headerText="Size">
            <p:cellEditor>
                <f:facet name="output"><h:outputText value="#{document.size}" /></f:facet>
                <f:facet name="input"><p:inputText value="#{document.size}" style="width:100%"/></f:facet>
            </p:cellEditor>
        </p:column>
        <p:column headerText="Type">
            <p:cellEditor>
                <f:facet name="output"><h:outputText value="#{document.type}" /></f:facet>
                <f:facet name="input"><p:inputText value="#{document.type}" style="width:100%"/></f:facet>
            </p:cellEditor>
        </p:column>
    </p:treeTable>
 </h:form>