Issue with @form in p:datatable

UI Components for JSF
Hamsterbau
Posts: 409
Joined: 28 Dec 2011, 17:44

10 Jan 2012, 13:41

Moin moin,

i have downstripped my problem to the following code:

Code: Select all

<ui:composition 
 	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
	<h:head>
		<title>Test page</title>
	</h:head>
	
	<h:body>
		<h:form id="pageForm">
			<p:commandButton type="submit" value="Start search" actionListener="#{myBean.updateEntries}" update="@form"/>
			
			<p:dataTable
				value="#{myBean.entries}"
				var="entry">
	
				<p:column>
					<f:facet name="header">
						<p:commandLink value="Update" update="@form"/>
					</f:facet>			
					<h:outputText value="Static"/>					
				</p:column>
			</p:dataTable>
		</h:form>
	</h:body>
</ui:composition>
If i replace the second @form in dataTable header with @all, the whole page is updated. But with the mentioned @form following Exception occours:

Code: Select all

12:03:39,793 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/my-app-1.0-SNAPSHOT].[Faces Servlet]] (http--0.0.0.0-8080-1) Servlet.service() for servlet Faces Servlet threw exception: javax.faces.FacesException: Cannot find component with identifier "pageForm" in view.
        at org.primefaces.util.ComponentUtils.findClientIds(ComponentUtils.java:249) [primefaces-3.1-SNAPSHOT.jar:]
        at org.primefaces.renderkit.CoreRenderer.buildAjaxRequest(CoreRenderer.java:223) [primefaces-3.1-SNAPSHOT.jar:]
        at org.primefaces.component.commandlink.CommandLinkRenderer.encodeEnd(CommandLinkRenderer.java:69) [primefaces-3.1-SNAPSHOT.jar:]
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) [jboss-jsf-api_2.1_spec-2.0.0.Beta1.jar:2.0.0.Beta1]
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1763) [jboss-jsf-api_2.1_spec-2.0.0.Beta1.jar:2.0.0.Beta1]
        at org.primefaces.component.datatable.DataTableRenderer.encodeColumnHeaderContent(DataTableRenderer.java:385) [primefaces-3.1-SNAPSHOT.jar:]
        at org.primefaces.component.datatable.DataTableRenderer.encodeColumnHeader(DataTableRenderer.java:361) [primefaces-3.1-SNAPSHOT.jar:]
        at org.primefaces.component.datatable.DataTableRenderer.encodeThead(DataTableRenderer.java:566) [primefaces-3.1-SNAPSHOT.jar:]
        at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:226) [primefaces-3.1-SNAPSHOT.jar:]
        at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:209) [primefaces-3.1-SNAPSHOT.jar:]
        at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:103) [primefaces-3.1-SNAPSHOT.jar:]
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) [jboss-jsf-api_2.1_spec-2.0.0.Beta1.jar:2.0.0.Beta1]
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1763) [jboss-jsf-api_2.1_spec-2.0.0.Beta1.jar:2.0.0.Beta1]
        at javax.faces.render.Renderer.encodeChildren(Renderer.java:168) [jboss-jsf-api_2.1_spec-2.0.0.Beta1.jar:2.0.0.Beta1]
Before updating to SNAPSHOT (what i did because of chaning datatable exporter), i only received a message for missing form in logfile. Seems to me like a bug, but perhaps i did something wrong? I also found similar issues, but only closed or set to invalid in Issue tracker:

http://code.google.com/p/primefaces/iss ... il?id=3155
http://code.google.com/p/primefaces/iss ... il?id=3164

By debugging primefaces i found out, that first call for commandButton is completly right. formatKeywords() delivers the clientId of form and component.findComponent() returns the HtmlForm object. But for the commandLink in the datatable the component.findComponent() call just returned null? In Version 3.0 this leads to following code (ComponentUtils.java, line 249):

Code: Select all

if(context.getApplication().getProjectStage().equals(ProjectStage.Development)) {
                       logger.log(Level.INFO, "Cannot find component with identifier \"{0}\" in view.", id);
}
buffer.append(id);
In Version 3.1-SNAPSHOT:

Code: Select all

throw new FacesException("Cannot find component with identifier \"" + id + "\" in view.");
Versions:
Primefaces 3.0 (only failure messages in logfile)
Primefaces 3.1-SNAPSHOT (from 10.01.2012 12 o'clock)
JBoss AS 7.0.2-Final

Please help,

Daniel

PS: If anyone knows how to contribute code to primefaces, please contact me (is PM possible in this forum?).
Primefaces 8.0.7 (PF Extensions 8.0)
JSF: Mojarra 2.3.2 (Spec 2.3) - running on WildFly 22

Hamsterbau
Posts: 409
Joined: 28 Dec 2011, 17:44

10 Jan 2012, 14:25

Replacing:

Code: Select all

<p:commandLink value="Update" update="@form"/>
with:

Code: Select all

<h:commandLink value="Update" render="@form"/>
and it works.

Also returns with an error:

Code: Select all

<p:commandButton value="Update" update="@form"/>
But i would prefer Primefaces tags, p:commandButton in particular (looks great).
Primefaces 8.0.7 (PF Extensions 8.0)
JSF: Mojarra 2.3.2 (Spec 2.3) - running on WildFly 22

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

10 Jan 2012, 14:45

Hi,

That's what I tried to say every time. Unfortunately, but PrimeFaces doesn't want to accept this issue in ComponentUtils.findClientIds(). There was a topic about this, but I can't find it (probably deleted). But ok, ich can repeat again. It's obviously that we can't pass clientId to findComponent() in a common case. Right? right. What does happens here. For the first p:commandButton you can do this because the "search expression" for findComponent() is the same as clienId of the form. Right? right. For the second p:commandButton you can't do this because the "search expression" for findComponent() should be :pageForm and that's not the clientId. If h:commandButton works with @form and p:commandButton not, then it's a bug in PF. I have also posted a modified findClientIds(), but I'm not up for posting it again.

P.S. What do you mean with code contribution? Do you want to deliver a patch oder commit some components?
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

10 Jan 2012, 14:49

Found http://paste.kde.org/177698/ With this findClientIds() you will find your form. It doesn't call findComponent() for formatted keywords again. You can try to convince Cagatay to modify findClientIds() like this in PF.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

Hamsterbau
Posts: 409
Joined: 28 Dec 2011, 17:44

10 Jan 2012, 15:16

Thanks, that fixed my Problem (i hope without side effects :mrgreen: )!

PS: Yes i would like to fix/enhance the datatable exporter, with additional attributes as well as a fixed behaviour for excluded columns. The PF source code looks really clean and in my opinion good to understand, so that i found the needed code fragments very fast.
Primefaces 8.0.7 (PF Extensions 8.0)
JSF: Mojarra 2.3.2 (Spec 2.3) - running on WildFly 22

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

10 Jan 2012, 15:22

Glad to help. You are building PF from source then. Nice.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

Max_S
Posts: 42
Joined: 24 Oct 2011, 18:05

10 Jan 2012, 16:53

Oleg wrote:Hi,

That's what I tried to say every time. Unfortunately, but PrimeFaces doesn't want to accept this issue in ComponentUtils.findClientIds(). There was a topic about this, but I can't find it (probably deleted). But ok, ich can repeat again. It's obviously that we can't pass clientId to findComponent() in a common case. Right? right. What does happens here. For the first p:commandButton you can do this because the "search expression" for findComponent() is the same as clienId of the form. Right? right. For the second p:commandButton you can't do this because the "search expression" for findComponent() should be :pageForm and that's not the clientId. If h:commandButton works with @form and p:commandButton not, then it's a bug in PF. I have also posted a modified findClientIds(), but I'm not up for posting it again.

P.S. What do you mean with code contribution? Do you want to deliver a patch oder commit some components?


This bug drove me crazy for a week.

I was trying to have those components on the page:
- a tree in which you select a item
- a button that transfer the selected item to a list
- the list
- for each element of the list: a button that delete the element from the list.

It's still unresolved, but (don't know how i did it) I found a "composition" of <h:form> and ajax update/process that is luckily working, even if with some complaints and warnings from PF ( "Cannot find component with identifier "listform" in view.|#] ").

I tried to make it work in a hundred other ways, changing the forms numbers, layout and the ajax update and process values, using forms with and without " : " .... but i couldn't get it to work in any way, against all the logic.

i post the page, in the case it can help in a similar case someone who don't wanna recompile pf or if someone can find a better (working) way to do this:

(the nodes data are objects, but with strings is the same, i checked)

Code: Select all

<h:form prependId="false" id="alberoform">
		<p:tree id="albero" value="#{productTreeBean.root}" var="node"
			selectionMode="single" selection="#{productTreeBean.selectedNode}">
			<p:treeNode>
				<h:outputText value="#{node.name}" />
			</p:treeNode> 
		</p:tree> 
		
		<p:commandButton id="treebtn" value="Display Selected" update=":listaform" />
</h:form>
		
<h:form id="listaform" prependId="false">
		<p:dataList id="lista" value="#{productTreeBean.selection}" var="element" itemType="none" >
		
			<f:facet name="header">
            	#{msg.products}
      		</f:facet> 
			<p:column>
				<p:commandLink title="Remove " value="X" styleClass="removebtn"
				 update="listaform" 
				actionListener="#{productTreeBean.removeFromSelection(element)}" />
			
			<h:outputText value="#{element.name}" />
			</p:column>
			
		</p:dataList>
</h:form>
		
GlassFish Server Open Source Edition 3.1.1 (12) / Mojarra 2.1.3 (FCS b02) / PrimeFaces 3.0.1 / Eclipse Indigo

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

10 Jan 2012, 17:29

i post the page, in the case it can help in a similar case someone who don't wanna recompile pf or if someone can find a better (working) way to do this:
There is only one better way. Don't use keywords @this, @form, @parent in PrimeFaces. This is a little limitation we can live with.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

Hamsterbau
Posts: 409
Joined: 28 Dec 2011, 17:44

10 Jan 2012, 17:53

Oleg wrote:There is only one better way. Don't use keywords @this, @form, @parent in PrimeFaces. This is a little limitation we can live with.
I think these keywords are a very neat enhancement in JSF2. Working with a bundle of IDs to refresh the whole form was sometimes really error-prone in JSF 1.2. I hope this will be "fixed" in a future release (perhaps 3.1?). Thanks again for your answer - helped a lot.
Primefaces 8.0.7 (PF Extensions 8.0)
JSF: Mojarra 2.3.2 (Spec 2.3) - running on WildFly 22

Max_S
Posts: 42
Joined: 24 Oct 2011, 18:05

10 Jan 2012, 18:10

Oleg wrote:
i post the page, in the case it can help in a similar case someone who don't wanna recompile pf or if someone can find a better (working) way to do this:
There is only one better way. Don't use keywords @this, @form, @parent in PrimeFaces. This is a little limitation we can live with.
Hi Oleg,
it's not just a matter of not using @form and so on, also with the appropriate form names like "listaform" "alberoform" and so on, the things didn't work.

I tried with one external form only, using the form names without colons in the ajax calls, or with 3 different forms using always the colons... with nested forms.. everything. it didn't work, I arrived at the point of writing the javascript ajax call primefaces.ab(...) in the onclick callback of the commandlink before luckily finding this "not perfect but working for now" solution.


Maybe i should have used another component like datatable instead of datalist, i didn't try it, i'll check when i'll have time.

However it would be better to fix the component if possible.



( Let me add: Despite these little bugs, Primefaces is great.)
GlassFish Server Open Source Edition 3.1.1 (12) / Mojarra 2.1.3 (FCS b02) / PrimeFaces 3.0.1 / Eclipse Indigo

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 19 guests