Hi Simon and Mick,
The method I gave works for me if the user has clicked in an input box and
presses return (tested in firefox and IE). If they click on some other
component outside of that form, it no longer works (which I think is
appropriate behaviour).
It doesn't work when the page first renders, but my onload() gives focus to
one of the input boxes anyway, so it doesn't cause problems for me. When my
page loads I can press enter and the default action occurs.
Note that I have type="button" on there. I believe the reason this works is
because in the resulting HTML, it does NOT get rendered as a submit button,
whereas my other actions do.
Eg:
<h:commandButton action="#{your.action}" image="/images/blank.gif"
type="button" tabindex="-1"/>
rendered as
<input id="_id18:_id19" name="_id18:_id19" type="image"
src="/spurwing/images/blank.gif" onclick="clear__5Fid18();" tabindex="-1" />
But <h:commandButton action="#{login.login}" value="Login" class="button" />
Rendered as
<input id="_id18:_id27" name="_id18:_id27" type="submit" value="Login"
onclick="clear__5Fid18();" class="button" />
I assure you it works, though I'm not sure why, and I don't really like it.
I'm using myfaces-1.1.4 and facelets.
Cheers,
Daniel.
-----Original Message-----
From: Simon Kitching [mailto:[EMAIL PROTECTED]
Sent: Tuesday, 5 December 2006 11:21 AM
To: MyFaces Discussion
Subject: Re: ENTER key with a single form but multiple actions
Hi,
I expect that the browser is simply invoking a method on the HTML
control that currently has the focus. If that HTML control happens to be
a submit button then its default behaviour in that situation is to
submit the associated form; if the control happens to be a text field
then it will have a different effect. This isn't anything to do with JSF.
Daniel, are you saying that your proposal works when the user clicks in
a text box then presses return, or that it allows the user to press
return immediately after the page is rendered (but not after they select
a text field or other control)?
Regards,
Simon
Daniel Young wrote:
> I use the nasty "1-pixel image" hack, putting it first in the form so
> the action I want ("your.action") is the default:
>
> <h:commandButton action="#{your.action}" image="/images/blank.gif"
> type="button" tabindex="-1"/>
>
> That should get you going for now, but if somebody does have A Better
> Way, I'd love to hear it.
>
>
> ------------------------------------------------------------------------
>
> *From:* Mick Knutson [mailto:[EMAIL PROTECTED]
> *Sent:* Tuesday, 5 December 2006 10:56 AM
> *To:* MyFaces Discussion
> *Subject:* ENTER key with a single form but multiple actions
>
>
>
> I have a form with multiple actions and I want a default action to
> happen when I click the enter key.
>
> Right now, I seem to get the 1st (default) action if I am NOT inside
> another component like a text field. But when I am inside another
> component, I get nothing submitted and have to manually mouse click the
> submit button.
>