15,000 Jobs Available in:
Java, ASP, C#, PHP, SQL, SAP, MySQL and many more.
- Class Quick -
The moose likes JSF and the fly likes f:ajax and client-side components Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSF
Reply Bookmark "f:ajax and client-side components" Watch "f:ajax and client-side components" New topic
Author

f:ajax and client-side components

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 565
why does jsf 2.0 ajax does not recognize client-side tags?


For example, this works:

Version 1:





while this is not working (because I use the tag html-tag <div> instead of a jsf-tag):


Version 2:




Why is Version 2 not working? Can I only use JSF-Tags in combination with f:ajax?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 11740

If you use the "Display page source" feature of your browser on both those pages, I think you'll see that the actual ID attributes of the JSF and div components are not quite the same.


A lot the of modern-day software development platforms are designed to permit parcelling out work to those with the best aptitude for it. A lot of modern-day business is predicated on making one person do all the work, regardless of aptitude.
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 565
I was looking at the html-source (via firebug) and cannot find a different ID:

ajax works with id h:panelGrid.

I replaced h:panelGrid with div (which has the same id):



and then I get this error:



Looking at the "Component Tree", it shows me my div:

This message was edited 3 times. Last update was at by nimo frey

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 11740

That punctuation is part of the ID. In other words: ":grid" is a completely different ID from "grid".
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 565
Yes, I have tried it with "grid":





but I get the same failure:



The debug-page offers the "Component Tree", I looked in it and found my id "grid". So it still exists! Strange..
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 11740

Not as strange as you think. Take a look at the HTML generated for a JSF control. You should see that the HTML ID for "grid" is actually something more like "formId:grid". That's because JSF supports something called "naming containers".

Which brings up a point. I hope you've got your commandButton in a JSF form! Otherwise it won't work right.
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 565

I found the problem.

The problem lies in the JSF 2.0 specification:

JSF 2.0 AJAX-Tag can only update JSF-Tags and not HTML-Tags.

So we have to enclose HTML-Tags (which should be updated) by a JSF-Tag (such as h:panelGrid).

 
 
subject: f:ajax and client-side components
 
MyEclipse, The Clear Choice