thunderhook
thunderhook

Reputation: 580

Primefaces Tree SelectListener resets other form inputs

I've got a problem with the SelectListener of the primeface component tree.

Update: What I want to do is creating a group and chosing a path from a tree. So I have the group name, and the tree for the path. After selecting a path, underneath the tree the selected path should be shown and updated by an AJAX request.

Here is a snippet of my code:

<h:form id="groupCreate">

   <p:inputText id="createGroupName" value="#{groupContainer.name}" />

   <p:tree id="pathTree" update="groupCreate" selectionMode="single"
         selection="#{groupContainer.selectedPath}" dynamic="false"
         value="#{groupContainer.rootNode}" var="node" cache="false"
         nodeSelectListener="#{groupContainer.onNodeSelect}">
      <p:treeNode>
          <h:outputText value="#{node[1]}" title="#{node[0]}" />
      </p:treeNode>
   </p:tree>

   <!-- Display selected Path from tree -->
   <h:outputText value="#{groupContainer.chosenPathString}/>

   <p:commandLink id="createButton" .../>

</h:form>

The onNodeSelect function in my bean looks like this:

public void onNodeSelect(NodeSelectEvent event) {  
    //get the selected data and set it
    this.chosenPathString = //selected Text;
} 

This generally works - means after the AJAX request the chosen path is shown. However if I input some text int the createGroupName input field, and afterwards select a node, after the AJAX request the createGroupName is set to null again.

So my AJAX request for updating the selected path name of the tree resets all my current typed values. After some debugging i found out that the AJAX request ignores all my typed values, because they are not commited yet (like they would be, if i submit the form). But how can I change my code to get this to work?

Any help would be appreciated, and sorry for my bad english in advance!

Upvotes: 0

Views: 1387

Answers (1)

Matt Handy
Matt Handy

Reputation: 30025

Your p:tree updates the whole form. This means that the form is re-rendered. In order to save other form input values you either need to submit the whole form onNodeSelect or update only the form elements that really need to be updated.

Assign an id to the h:outputText for the selected path and change your update attribute of p:tree, such as:

<h:form id="groupCreate">

   <p:inputText id="createGroupName" value="#{groupContainer.name}" />

   <p:tree id="pathTree" update="choosenPath" selectionMode="single"
         selection="#{groupContainer.selectedPath}" dynamic="false"
         value="#{groupContainer.rootNode}" var="node" cache="false"
         nodeSelectListener="#{groupContainer.onNodeSelect}">
      <p:treeNode>
          <h:outputText value="#{node[1]}" title="#{node[0]}" />
      </p:treeNode>
   </p:tree>

   <!-- Display selected Path from tree -->
   <h:outputText id="choosenPath" value="#{groupContainer.chosenPathString}/>

   <p:commandLink id="createButton" .../>

</h:form>

Upvotes: 4

Related Questions