JavaBeginner
JavaBeginner

Reputation: 81

Pressing enter to click on hidden button without using JS on a jsf page?

I have a jsf page where I have several 's. When I press enter I want a particular button to be clicked - and this button is hidden. Is there a way to do this without using JS? I know if i place the button as the first button on the page, it will be clicked by default - but it does not seem to work.

Here is the sample code. I want the "hiddenButton" to be clicked on Enter.

<h:form>
    <h:commandButton id="button1" action="#{bean.action1}" /> 
    <h:commandButton id="button2" action="#{bean.action2}" /> 
    <h:commandButton id="button3" action="#{bean.action3}" />
    <h:commandButton id="hiddenButton" action="#{bean.hiddenAction}" style="display:none;"/> 
<h:form> 

Upvotes: 1

Views: 429

Answers (1)

BalusC
BalusC

Reputation: 1108922

Is there a way to do this without using JS?

Not if you want to support all browsers.


I know if i place the button as the first button on the page, it will be clicked by default - but it does not seem to work.

This works only in Firefox, not in Chrome (Webkit) or IE. If you replace display:none by visibility:hidden, then it'll also work in Chrome, but still not in IE.

So, if you want to support all browsers, JS is your best bet. There may be better solutions depending on the concrete functional requirement, which you didn't tell anything about in the question.

Upvotes: 1

Related Questions