aspose file tools*
The moose likes JSF and the fly likes Need a fix for <a4j:commandLink> to both run an action and oncomplete event. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Need a fix for <a4j:commandLink> to both run an action and oncomplete event." Watch "Need a fix for <a4j:commandLink> to both run an action and oncomplete event." New topic
Author

Need a fix for <a4j:commandLink> to both run an action and oncomplete event.

Dan Acuff
Ranch Hand

Joined: Jul 13, 2009
Posts: 62
Hi everyone and thank you for your time.

Our website runs on Java SEAM/JSF 1.2/RichFaces3.x.x and Facelets is there on the front-end as well.

I mostly work on another platform and language but am transitioning to this platform, so pardon me if I lack clarity in any areas.

I want to create a one text input form with a submit button, using ajax4jsf or a4j, and then once the bean.method is fired and a record stored in the DB - I need to rename the wrapper div's id attribute and insert some new innerHTML.

I was wondering if you all had suggestions on how to do this with your own approach?

and/or also I can show my try at tackling this simple problem next:
--------------------------------------------------------------------------------------------------

I have some code that I have managed to get working in Chrome, IE8, but not FireFox. BTW: my a4j: namespace is a: so that is what a: is in the code.

In FireFox, the correctly submits a record to the database and does not return any values.

Next the oncomplete attribute fires an event to a JavaScript function - it's job is to replace the wrapper div id and load the new content.

First a portion of what I have in the front page code:



And then the Javascript functions:



Hopefully there is enough information for us to at least look at the reason it failed in FireFox, but let me know if more information is needed. The Method in the bean is confirmed to work. And not a good idea to share it anyway.

Thanks all very much!

A VERY IMPORTANT P.S >>

Ok so my testing involves making sure you can BOTH click the button to submit your email AND type your email and just hit the Enter key. The only thing of all the browsers tested that failed is FireFox 14 (ithink) and it failed when typing and pressing Enter Key. It actually works in all browsers if you click the Submit button.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

There are major differences between IE and Firefox when it comes to handling the ENTER key on a form.

Beyond that, a couple of minor observations:

1. I don't think "return false();" has meaning in oncomplete. onsubmit would be different.

2. RichFaces comes with some JSF-friendly macros that make it easier to access JSF DOM objects.

3. RichFaces also comes with a built-in (if antique) copy of jQuery that can make it easier to rearrange DOM objects in a browser-portable manner (and less code than raw javascript).

4. I'd be cautious about actually changing the IDs on DOM object, regardless.

5. Usually when I make the View mutable - which I rarely do on account of it's not generally recommended - I prefer to bind the root object of of mutating part of the View to a backing bean, let the backing bean meddle with the UI elements, and, when using AJAX, let the RichFaces reRender kick off the UI update. That way I don't need any oncomplete= javascript.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Need a fix for <a4j:commandLink> to both run an action and oncomplete event.