You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Mick Knutson <mi...@gmail.com> on 2006/12/05 01:55:50 UTC

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.


-- 

Thanks

DJ MICK
http://www.djmick.com
http://www.myspace.com/mickknutson

Re: ENTER key with a single form but multiple actions

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi Mick!
> I have a form with multiple actions and I want a default action to
> happen when I click the enter key.
Have a look at our sandbox component submitOnEvent.
It has various modes to determine which action to trigger. The simplest
might be to add it as child to the commandButton which should be the
default.
You'll find its wiki page here [1]

Ciao,
Mario

[1] http://wiki.apache.org/myfaces/SubmitOnEvent


Re: ENTER key with a single form but multiple actions

Posted by Mick Knutson <mi...@gmail.com>.
I just tested it when I was in an input field, and it does not work. Nothing
happends at all. Just like before.


On 12/4/06, Simon Kitching <si...@rhe.co.nz> wrote:
>
> 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:mickknutson@gmail.com]
> > *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.
> >
>



-- 

Thanks

DJ MICK
http://www.djmick.com
http://www.myspace.com/mickknutson

RE: ENTER key with a single form but multiple actions

Posted by Daniel Young <dy...@synyati.com.au>.
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:simon.kitching@rhe.co.nz] 
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:mickknutson@gmail.com]
> *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.
> 



Re: ENTER key with a single form but multiple actions

Posted by Simon Kitching <si...@rhe.co.nz>.
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:mickknutson@gmail.com]
> *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.
> 

RE: ENTER key with a single form but multiple actions

Posted by Daniel Young <dy...@synyati.com.au>.
Hi Mick,

 

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.

 

Cheers,

Daniel.

 

  _____  

From: Mick Knutson [mailto:mickknutson@gmail.com] 
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. 


-- 

Thanks

DJ MICK
http://www.djmick.com
http://www.myspace.com/mickknutson