I'm sure a lot of people have asked this, but here is the problem I'm having, and I'm not sure exactly how to solve it. It's probably something simple that I'm just missing conceptually, but hopefully you guys know the answer...
OK... I have a form, and in the form I have two commandButton components. One is "Back" and has its immediate attribute set to "true". The other button is "Continue", and its action attribute is set to call a method on a bean. Both work great if the user *clicks* on the respective buttons.
However, the problem is that if the user hits the *Enter* key, the form submits (expected), but it behaves as if the "Back" button was clicked. Is there a way to force the submit of a form to always do the same action of the "Continue" button (i.e. call the method on the bean)?
Thank you for the suggestions. Unfortunately I can't do Bauke's suggestion since the design is rather specific in its placement of the buttons.
I tried out ali's suggestion, and it seems to not work as expected. I made the continue button's id "submit", but it still triggers the "Back" commandButton.
So it looks like I'm down to trying Anu's suggestion, or some variant of it. Let me know if anyone has any other suggestions.
[EDIT] Anyone have any good resources (links, etc.) for doing the kind of thing Anu is suggesting? I haven't "taken the plunge" yet with embedding JavaScript into my JSF pages yet (other than what gets automatically generated) - is that a really daunting task or is it fairly straightforward? [/EDIT]
Thanks again!
///eks [ December 20, 2006: Message edited by: evan k. stone ]
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
0
Try putting the back button in a separate h:form.
Ali Gohar
Ranch Hand
Joined: Mar 18, 2004
Posts: 572
posted
0
As far as javascript is concerned you can do something like this
Here i have used "onklick" instead of "onclick" because it is not allowing me to use that one. so just replace it
Now write the javascript function
If you are using the controls inside a <h:form> tag then you will have to append the form id with the control name to form that. For example if your form name is myForm then you will write the if condition in javascript as