Advice on using Javascript "this.form.submit" with a JSF form
843844Feb 26 2007 — edited Jun 1 2007Hello 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