wood burning stoves*
The moose likes JSF and the fly likes JSF 2.0  - replacing JS Alert Box with what? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF 2.0  - replacing JS Alert Box with what?" Watch "JSF 2.0  - replacing JS Alert Box with what?" New topic
Author

JSF 2.0 - replacing JS Alert Box with what?

Deniz Atak
Ranch Hand

Joined: Jun 29, 2011
Posts: 30

I have a form in JSF 2.0 whose input fields have validation checks and there is a submit button. Right now when I click on the submit button I get an alert box (generated by JS) saying that my report order is being processed (to give a feedback to the user). This alert box is displayed without the neccessary validation checks for the input fields. I can do the validation check in the back bean but how can I replace the behaviour of my alert box? Can I trigger a JS action from back bean? I spent quite a lot time in web searching for a solution to this problem. If anyone has any reccommendation about which way to proceed, I will be happy to listen. Thanks in advance.
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

You want the JS to do the validation or the JSF?

If you want the JSF to do the validation you can add the required parameter in your inputText fields.

If you want the JS to do the validation you can add the code and invoke this on the onClick event of the commandButton.


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Deniz Atak
Ranch Hand

Joined: Jun 29, 2011
Posts: 30
I am already doing the validation in JSF. I just want to display an (like you do with JS) alert box to say that "The report is being generated" after the validation if everything is fine. How can I do that?
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

You can do a Ajax call and with the reply of it you would update the in the messages component.
Deniz Atak
Ranch Hand

Joined: Jun 29, 2011
Posts: 30
do you mean an ajax call after the button click?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15646
    
  15

Deniz Atak wrote:do you mean an ajax call after the button click?


No, he means do an AJAX call ON the button click.

In other words, override the normal "action=" method, which is non-AJAX by defining something like this:

onsubmit="ajaxSubmit(); return false;"

The "ajaxSubmit function is a JavaScript function that presents the "processing report" text, does the AJAX form submit, and then clears the message when the submit has responded. jQuery can help do all that. The "return false" keeps the normal action from being performed and thereby submitting the form twice.

OR, there are alternatives. JBoss RichFaces is an extension tagset that provides all this straight out of the box using only JSF tags without you having to write any JavaScript code yourself. Probably some of the other extension tagsets do, too, but that's the one I use routinely, and the "a4j:status" tag has been a boon to me more than once.


Customer surveys are for companies who didn't pay proper attention to begin with.
Deniz Atak
Ranch Hand

Joined: Jun 29, 2011
Posts: 30
Hi Tim,

thanks for your detailed answer. I tried adding f:ajax tag (because my component library is a little bit old - Woodstock, and I couldn't find enough documentation about Ajax support of Woodstock). But I got:



message. But my project is JSF 2.0. Isn't there a support for Ajax in JSF 2.0?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF 2.0 - replacing JS Alert Box with what?
 
Similar Threads
front-end validation in struts jsp page
AJAX, JSF and security
Apache Commons Validation Framework
Confirm message on submit
h:commandButton type