update="@all" not updating browser DOM

Components, Ajax Framework, Utilities and More.
notizklotz
Posts: 9
Joined: 20 Jan 2012, 12:44

02 Mar 2012, 12:32

Hi

I've got a problem in using update="@all" to let Primefaces update the whole page. Given this example:

Code: Select all

<h:body id="myBody">
	<h:panelGroup id="bodyChildPanel">
		<h:form id="myform">
			<h:outputText id="outputCounter" value="#{myBean.counter}"/><br/>
			<h2>Working:</h2>
			<p:commandButton action="#{myBean.increment}" update="outputCounter" value="Increment (outputCounter)"/>
			<p:commandButton action="#{myBean.increment}" update="@form" value="Increment (@form)"/>
			<p:commandButton action="#{myBean.increment}" update=":bodyChildPanel" value="Increment (bodyChildPanel)"/>
			<h2>Defunct (Value correct in Ajax-Response but browser view not updated):</h2>
			<p:commandButton action="#{myBean.increment}" update=":myBody" value="Increment (myBody)"/>
			<p:commandButton action="#{myBean.increment}" update="@all" value="Increment (@all)"/>
			<p:commandButton action="#{myBean.increment}" value="Increment (p:ajax @all)">
				<p:ajax update="@all"/>
			</p:commandButton>
		</h:form>
	</h:panelGroup>
</h:body>
The Action method of the buttons just increase the "counter" value in the backing bean. In all cases the Ajax response contains the correctly increased value so I it's not a server-side problem. However, as soon as the updated region in the Ajax response includes the <body> no DOM changes seem to be applied.

Tested with:
Primefaces 3.1.1 and 3.2-SNAPSHOT download from 2nd March 2012
Mojarra 2.1.7
Tomcat 7.0.23

A feasible workaround for this problem is to put a <h:panelGroup> just below <h:body> and us this as update-target. However, this slightly modfies the HTML structure and @all would be more intuitive.

Does anybody have this problem too? Is this a general limitation of how Primefaces works or just a bug? I can attach a fully working minimalistic example webapp (.war) demostrating the problem if desired.

Cheers
Adrian

User avatar
optimus.prime
Prime
Posts: 17717
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

02 Mar 2012, 12:33

PrimeFaces does not support update="@all" because update="@all" is fundamentally wrong.

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

02 Mar 2012, 13:30

I suggest to throw an exception if update="@all"
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

notizklotz
Posts: 9
Joined: 20 Jan 2012, 12:44

02 Mar 2012, 14:29

Hi Optimus, Oleg

Thanks for your responses! I agree that @all is not a common or preferrable case, it just happend in a project I have to migrate to Primefaces.

I like Oleg's suggestion to throw an exception in this case. Like this it's clear that it's not supported. If possible, the exception should also be thrown if udpate="idOfMyBody" is used. Should I make a feature request for this?

Cheers
Adrian

tandraschko
PrimeFaces Core Developer
Posts: 3296
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

02 Mar 2012, 14:36

Why thrown an exception if update="idOfMyBody"?
Always Bet On Prime (+ Extensions)!

Thomas Andraschko
PrimeFaces Developer | PrimeFaces Extensions Founder
Apache OpenWebBeans PMC | Apache DeltaSpike PMC | Apache MyFaces PMC

Personal Blog: http://tandraschko.blogspot.de/

notizklotz
Posts: 9
Joined: 20 Jan 2012, 12:44

02 Mar 2012, 14:45

zoigl wrote:Why thrown an exception if update="idOfMyBody"?
Because it has the same effect as if using @all: The Ajax response looks correct but the browser DOM is not updated if updatepoints to the body:

Code: Select all

<h:body id="idOfMyBody">

User avatar
optimus.prime
Prime
Posts: 17717
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

02 Mar 2012, 14:48

Does h:body id generate?

Code: Select all

<body id="sth">

notizklotz
Posts: 9
Joined: 20 Jan 2012, 12:44

02 Mar 2012, 15:24

optimus.prime wrote:Does h:body id generate?

Code: Select all

<body id="sth">
With Mojarra: No the ID of the body element is not rendered. You're right, i didn't check that... So with Mojarra updating the body just can't work because the ID is missing.

With MyFaces 2.1.6 the ID is rendered for the body element and the update works, but only once. When I check with Firebug, the <body> element itself is completely missing in the browser DOM after the Ajax call :shock: All child elements are direct descendants of <html>...

Thinking about this it's actually a horrible thing to replace the whole body element in the DOM. So in the case of update="idOfMyBody" I don't expect Primefaces to throw an exception because it doesn't have to do anything with Primefaces at all.

User avatar
optimus.prime
Prime
Posts: 17717
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

02 Mar 2012, 15:31

Workaround is nest an outputpanel inside body and update that.

Code: Select all

<h:body>
   <p:outputPanel id="all" layout="block">
   </p:outputPanel>
</h:body>
I wouldn't mess with body element.

notizklotz
Posts: 9
Joined: 20 Jan 2012, 12:44

02 Mar 2012, 15:36

optimus.prime wrote:Workaround is nest an outputpanel inside body and update that.

Code: Select all

<h:body>
   <p:outputPanel id="all" layout="block">
   </p:outputPanel>
</h:body>
I wouldn't mess with body element.
Yes, this is what I'm currently using until all pages in the project are "sanitized" and use proper update targets. As I wrote in my orginal post this approach has the slight drawback of modifying the HTML structure by adding an extra <span> or <div> below the <body> but this is not a problem in my case. Thanks!

Post Reply
  • Information
  • Who is online

    Users browsing this forum: Bing [Bot] and 26 guests