How to update component on clientside in primefaces

jsfjsf-2primefaces

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

Tree:

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

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

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="#{testGroupController.selected.name}" title="#{bundle.CreateTestGroupTitle_name}" />
                    <h:inputHidden  id="parentId" value="#{testGroupController.selected.parentId}" />

                </p:panelGrid>
                <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()"/>
            </h:panelGroup>

        </h:form>

    </p:dialog> 

I want that click on

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

Will set value of:

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

UPDATE

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="TestGroupCreateDialog.show()">
                            <f:attribute name="rawParentId" value="#{node.getIdTestGroup()}" />
  </p:commandButton>

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.

Edit

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

process="myInputId"

Example

<h:form>
    <h:inputText id="input" 
                 value="#{bean.value}" />
    <h:outputText id="output" 
                  value="#{bean.value}" />
    <p:commandButton process="input"
                     update="output"
                     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