Using "onkeyup" to update "p:tree"

UI Components for JSF
Post Reply
RomanSmi
Posts: 4
Joined: 20 Jan 2011, 16:05

20 Jan 2011, 16:51

Hey,

I'm using Primefaces 2.2 RC2.
I have some trouble in using the attribute "onkeyup" in "inputText".

View:

Code: Select all

<p:layout style="width:1238px;height:770px;">  
    <p:layoutUnit position="left" width="250" scrollable="true">  
	<p:tree id="monitorModelTree" value="#{monitorModelEditor.root}" var="node"
	            nodeSelectListener="#{monitorModelEditor.onNodeSelect}"
	            nodeExpandListener="#{monitorModelEditor.onNodeExpand}"
	            nodeCollapseListener="#{monitorModelEditor.onNodeCollapse}"
	            selectionMode="single" update="editorLayout">
		<p:treeNode>
			<h:outputText value="#{node}" styleClass="cur"/>
		</p:treeNode>
					
		<p:treeNode type="monitorModel">
			<h:graphicImage library="images" name="monitorModel.png" />
			<h:outputText value=" #{node}" styleClass="cur" />
		</p:treeNode>
                                 ...
	</p:tree>
    </p:layoutUnit>

    <p:layoutUnit id="editorLayout" position="center">

  	<p:panel id="monitorModelDetailsPanel" header="Monitor Modell Details" 
                              rendered="#{monitorModelEditor.monitorModelNodeSelected}">
	    <h:panelGrid columns="2">
		<h:outputText value="Name:" />
		<h:inputText id="monitorModelName" value="#{monitorModelEditor.currentModel.name}"
		  	    onchange="newMonitorModelName()" onkeyup="monitorModelName()"/>
		<p:remoteCommand name="monitorModelName" update="monitorModelTree" />
		<p:remoteCommand id="saveNewMonitorModelName" name="newMonitorModelName"
                                                               process="@this,monitorModelName"
			              actionListener="#{monitorModelEditor.newMonitorModelName}" />
	</h:panelGrid>					
  	</p:panel>
	...
    </p:layoutUnit>
</p:layout>  
On the left side there is a tree with some elements and on the right side there is an area, where a user can edit the elements. For example, if the user click on the "treenode" with the "type" "monitorModel", on the right side he can change the name of the element. Therefore I'm using in the Backing-Bean a boolean Flag "monitorModelNodeSelected" (which will be set in the method "onNodeSelect"). So, if the user click on the "monitorModel"-element "p:layout" with "id=editorLayout" will be updated and the panel "id=monitorModelDetailsPanel" will be rendered (because the boolean flag is set to true).
To change the name of the element there is a "h:inputText" ("id=monitorModelName") with the attributes "onchange" and "onkeyup". Therefore I'm using the remoteCommand... "onchange" triggers the remoteCommand "newMonitorModelName" to check the new name of the element (is it okay or not). "onkeyup" triggers the remoteCommand "monitorModelName" and update the tree on the left side, so that the name of the element will be shown.
The "onchange"-event works fine, but the "onkeyup"-event does not work. I'm getting always a NullPointerException:

Code: Select all

20.01.2011 15:09:21 org.apache.catalina.core.StandardWrapperValve invoke
SCHWERWIEGEND: Servlet.service() for servlet SpringDispatcherServlet threw exception
java.lang.NullPointerException
	at org.primefaces.component.tree.Tree.processUpdates(Tree.java:315)
	at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1109)
	at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1109)
	at javax.faces.component.UIForm.processUpdates(UIForm.java:268)
If and only if I press the key "F5" to refresh the page, then the "onkeyup"-event works fine. But always after I pressed the key "F5"...

Is there any work-around? What is wrong with my code?

Thanks a lot for your help...

With best wishes,
Roman

RomanSmi
Posts: 4
Joined: 20 Jan 2011, 16:05

21 Jan 2011, 12:10

Have anybody out there a idea to solve this problem? Do you need more information?

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

21 Jan 2011, 13:08

Can you try with 2.2 snapshot?

RomanSmi
Posts: 4
Joined: 20 Jan 2011, 16:05

21 Jan 2011, 14:48

It does not help. It is the same behavior. Any other idea?

RomanSmi
Posts: 4
Joined: 20 Jan 2011, 16:05

26 Jan 2011, 11:16

You have to use the "selection"-Attribute in "<p:tree>", then the treeNode will be updated...

Code: Select all

<p:tree id="monitorModelTree" value="#{monitorModelEditor.root}" var="node"
	...
	selection="#{monitorModelEditor.selectedEntity}">
	...
Thanks for your help...

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 35 guests