How to update component on clientside in primefaces


I want to create add children button with dialog form feature.

On the page there are tree and modal dialog form. On every node of tree will be the create child button. If you click on create child button, there will be shown modal form, where parentId will be set as id of node where button was clicked


 <h:form id="TestGroupListForm">    
    <p:tree value="#{testTreeController.root}" var="node" dynamic="true" cache="false"  
                    selectionMode="single"  selection="#{treeBean.selectedNode}" id="tree">  

                    <h:outputText value="#{node.getName()}" />  <p:commandButton id="createButton#{node.getIdTestGroup()}" icon="ui-icon-plus"   value="#{bundle.Create}"  update="tree" oncomplete=""/>

Dialog Box:

        <h:form id="TestGroupCreateForm">

            <h:panelGroup id="display">
                <p:panelGrid columns="2" >

                    <p:outputLabel value="#{bundle.CreateTestGroupLabel_name}" for="name" />
                    <p:inputText id="name" value="#{}" title="#{bundle.CreateTestGroupTitle_name}" />
                    <h:inputHidden  id="parentId" value="#{testGroupController.selected.parentId}" />

                <p:commandButton actionListener="#{testGroupController.saveNew}" value="#{bundle.Save}" update="display,:TestGroupListForm:tree,:growl" oncomplete="handleSubmit(xhr,status,args,TestGroupCreateDialog);"/>
                <p:commandButton value="#{bundle.Cancel}" onclick="TestGroupCreateDialog.hide()"/>



I want that click on

<p:commandButton id="createButton#{node.getIdTestGroup()}" icon="ui-icon-plus"   value="#{bundle.Create}"  update="tree" oncomplete=""/>

Will set value of:

<h:inputHidden  id="parentId" value="#{testGroupController.selected.parentId}" />


I have to use action listener testGroupController.nodeListener to set parentId of the new item.

    <p:commandButton process="@this" id="createButton" actionListener="#{testGroupController.nodeListener}" icon="ui-icon-plus"   value="#{bundle.CreateGroup}"  update=":TestGroupCreateForm" oncomplete="">
                            <f:attribute name="rawParentId" value="#{node.getIdTestGroup()}" />

Best Solution

You can add parentId to the existing update= attribute like so:

update="tree parentId"

This will render parentId and set its value to testGroupController.selected.parentId.


You can process any values from the UI to the been too, by using:



    <h:inputText id="input" 
                 value="#{bean.value}" />
    <h:outputText id="output" 
                  value="#{bean.value}" />
    <p:commandButton process="input"
                     value="Submit" />

Upon clicking your button, the value of id="input" will be set in bean.value (as ordered by process="input"). Next your id="output" will be rendered (or updated) with bean.value (as ordered by update="output").

Related Question