wood burning stoves*
The moose likes JSF and the fly likes Ajax and the message tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Ajax and the message tag" Watch "Ajax and the message tag" New topic
Author

Ajax and the message tag

Rob Micah
Ranch Hand

Joined: Aug 30, 2011
Posts: 94
I have an inputText with an ajax element hooked to its keyup event. I have a panelGroup below the inputText element holding a message tag. What I want to do is hide the panelGroup when there is no message for the inputText. What I have attempted to do is create a listener method that checks the valid status and uses that as the rendered attribute on the panelGroup. Unfortunately if validation fails the Invoke Application phase is never reached and my listener never executes. And setting the immediate attribute to true on the ajax element causes the listener to execute before validation. So what is the best way to do this?A
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

I'm not sure how the inputText field is being used in your case, but would its onblur or onchange javascript events be any possible triggers to hide/show the panelGroup?
Rob Micah
Ranch Hand

Joined: Aug 30, 2011
Posts: 94
How would I show/hide the panelGroup? I'm attempting to do it with an ajax listener method. But my listener method won't execute at the right time. If validation fails then the Invoke Application phase never executes and so my listener doesn't either. If I set the immediate attribute then the listener executes before validation.
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

How about always show the panelGroup, but you use CSS to hide it by default, and use Javascript to check inputText and show/hide the panelGroup based in the inputText value? You can use the onload even for the first time the page is loaded, then onblur or onchange events on inputText after the page is loaded (I'm assuming you can edit the value in inputText after the page loaded). Anyway, this is just a suggestion. There's probably other ways to handle it, or it may not work exactly for your scenario.
Rob Micah
Ranch Hand

Joined: Aug 30, 2011
Posts: 94
Koen Aerts wrote:How about always show the panelGroup, but you use CSS to hide it by default, and use Javascript to check inputText and show/hide the panelGroup based in the inputText value? You can use the onload even for the first time the page is loaded, then onblur or onchange events on inputText after the page is loaded (I'm assuming you can edit the value in inputText after the page loaded). Anyway, this is just a suggestion. There's probably other ways to handle it, or it may not work exactly for your scenario.


That's what I thought, too. But I can't do that for a couple reasons. The first is that there is currently a bug in Mojarra where using an ajax onload event on the body element doesn't work. Also using the javascript approach means I have to duplicate my validation logic: once in the bean and once in the javascript. I did something like this at first but it became too unmanageable.
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

Rob Micah wrote:The first is that there is currently a bug in Mojarra where using an ajax onload event on the body element doesn't work.

Any way of using a newer/older version of Mojarra?

In the past I had issues with some of the Javascript that came from Tomahawk but I was able to fix the javascript code. Then I used the addResources="false" attribute to the Tomahawk tag (I think it was a t:inputCalendar) so that it would not generate its built-in javascript code anymore, and I changed my HTML header to include the fixed copy of the Tomahawk javascript, which I had saved with my other javascript files. Not sure if a similar approach works for Mojarra.
Rob Micah
Ranch Hand

Joined: Aug 30, 2011
Posts: 94
I wish there were but I don't think it's been fixed: http://java.net/jira/browse/JAVASERVERFACES-1781

But I may have found a way to do this another way. It appears, and I could be wrong about this, that if you stack <ajax> tags for the same event they execute in order. That would solve my problem. But I can't find documentation to prove this. Any idea?
 
 
subject: Ajax and the message tag
 
Similar Threads
how to bind value attribute inside another component binding attribute
setting width in panelGroup, panelGrid
What is the Logic for splitting the JSF Core and HTML tag libraries?
Change Component Style on Validation
Ajax & Myfaces problem - pages reloads with commandButton.