Edit tree node question

UI Components for JSF
Post Reply
ozbluesky
Posts: 20
Joined: 30 Oct 2010, 06:39

30 Dec 2010, 09:30

Hi,

I have a page with a <p:tree>. On click of the node, node detail is shown on the same page. When another node is selected, node detail section is refreshed with new node info. I followed show case tree - AJAX selection sample code, it works fine when the detail section is view only.

Then I changed the detail section to updateable input form, I encountered a problem.

Code: Select all

	<p:tree value="#{treeBean.root}" var="node"
		selectionMode="single" selection="#{treeBean.selectedNode}"
                nodeSelectListener="#{treeBean.onNodeSelect}>
		<p:treeNode>
			<h:outputText value="#{node}" />
		</p:treeNode>
	</p:tree>
  ...
<h:inputText value="#{myBean.editingData.name}" />
I think this is the scenario:
1. Tree node A is selected, treeBean.selectedNode is set to A
2. nodeSelectListener treeBean.onNodeSelect is invoked. myBean.editingData is set to A
3. Detail section is rendered, input field value is name of A
4. Tree node B is selected. treeBean.setSelectedNode is invoked. treeBean.selectedNode set to new node B.
5. nodeSelectListener treeBean.onNodeSelect is invoked. myBean.editingData is set to B
6. Since the <h:inputText > field has value as name of A, editingData.setName(A) is invoked, but editingData is already changed to B in step 5.

Here come to the problem that node B is assigned node A's name, which is not intended.

Any idea how to avoid this problem? For example can I delay invoke of nodeSelectListener ?

Thanks.
PrimeFaces 2.2.1/3.0M1, JSF2.0, Netbean 6.9.1 GlassFishes 3

ozbluesky
Posts: 20
Joined: 30 Oct 2010, 06:39

31 Dec 2010, 02:22

Some findings here:

Update to backing bean is done in JSF update module value phase.
Adding facesContext.renderResponse() in nodeSelectListener will skip update module phase, so that backing bean won't get updated, and screen will be navigated away.

However, my tree also has attribute onselectComplete="updateCenter()", which calls <p:remoteCommand name="updateCenter" update="contentUnit" />
The reason is because my page is using <ui:include > to "dynamically" load different <ui:composition> base on tree node selected.

When remoteCommand reloads the page, JSF life cycle happens again, and bean is updated in update module phase. I tried to put actionListener in <p:remoteCommand> to call facesContext.renderResponse() hoping to skip the update phase. However, p:remoteCommand actionListner is not invoked.

Code: Select all

   <p:tree value="#{treeBean.root}" var="node"
      selectionMode="single" selection="#{treeBean.selectedNode}"
                nodeSelectListener="#{treeBean.onNodeSelect}
                update="@none" onselectComplete="updateCenter()" >
      <p:treeNode>
         <h:outputText value="#{node}" />
      </p:treeNode>
   </p:tree>
<p:remoteCommand name="updateCenter" update="contentUnit" />
  ...
<h:inputText value="#{myBean.editingData.name}" />
Am I going to right direction? And what's the proper way to invoke actionListner on p:remoteCommand?
PrimeFaces 2.2.1/3.0M1, JSF2.0, Netbean 6.9.1 GlassFishes 3

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests