Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Advice on using Javascript "this.form.submit" with a JSF form

843844Feb 26 2007 — edited Jun 1 2007
Hello all,

I'm sure that someone will point out that this is already covered somewhere... but I posted a problem I was having at

http://forum.java.sun.com/thread.jspa?threadID=5140905&tstart=15

and no one answered, so even if it is covered, it doesn't hurt to say it again.

The issue is this: sometimes we want to design forms that submit themselves in response to certain events, as in "onchange" or "onclick" etc. To these events, we add a bit of Javascript that says something like "this.form.submit()".

I ran into a problem recently where this was not working for me: the form would be submitted and go through validation BUT it would not invoke the specified action (a method in a backing bean as is typical).

Reason for the problem: pressing the submit button" will send along with the form a parameter that represents the button. But using Javascript to send off a submit() will not* include that parameter - and JSF needs that parameter it seems to invoke the backing bean; if the parameter is there, it will invoke the method, otherwise no. Mind you, the entire JSF lifecycle will occur, even going into Invoke Application - but it just won't be invoked.

Solution: if you want the submission to really occur, and invoke the backing bean method, before doing a this.form.submit, add a line where you alter the action to include a bogus submit parameter as part of the query string:

this.form.action = this.form.action + "?formSubmit=Value"

If this helps anyone, great. Took me a couple of days to figure out something that is probably self-evident to many of you. Oh well....

-A

Message was edited by:
bland999
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 29 2007
Added on Feb 26 2007
4 comments
199 views