Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ajax and the message tag

 
Rob Micah
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic