aspose file tools*
The moose likes JSF and the fly likes How to specify default button in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to specify default button in JSF" Watch "How to specify default button in JSF" New topic
Author

How to specify default button in JSF

Zane Wlight
Greenhorn

Joined: Aug 07, 2008
Posts: 5
hi all,

The problem is I got two submit buttons in a page, one for saving form, one for searching. The save button at the top and search one at the bottom. You know, the default would be save button when I press "Enter" key. Now if I want to trigger search button after the event, What should I do?

Thank you in advance,
Zane
[ October 14, 2008: Message edited by: Zane ]

good is good
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

We faced similar problem in our project. We also had two buttons one for continue and other for 'Go BAck'. We wrote javascript to trap the pressing of enter key and submitted the form on the event.


My Blog SCJP 5 SCWCD 5
Zane Wlight
Greenhorn

Joined: Aug 07, 2008
Posts: 5
Originally posted by Himanshu Gupta:
We faced similar problem in our project. We also had two buttons one for continue and other for 'Go BAck'. We wrote javascript to trap the pressing of enter key and submitted the form on the event.


Thank you for your advice, Himanshu. But, You know, JS is not that graceful in JSF page. Any simple solution?
Abdul Shams
Greenhorn

Joined: Oct 12, 2008
Posts: 6
Try putting each button in an h:form

put the button you want to be default in the same form as the fields you have and put the other button in another h:form.

Hope it helps
[ October 14, 2008: Message edited by: Abdul Shams ]
Zane Wlight
Greenhorn

Joined: Aug 07, 2008
Posts: 5
Originally posted by Abdul Shams:
Try putting each button in an h:form

put the button you want to be default in the same form as the fields you have and put the other button in another h:form.

Hope it helps

[ October 14, 2008: Message edited by: Abdul Shams ]


Thank you Abdul, but when I do it like this:

<h:form>
<h:form>
save button
</h:form>
<h:form>
search button
</h:form>
</h:form>

the save button wouldn't work. Any idea?
[ October 14, 2008: Message edited by: Zane Wlight ]
Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
Check out

http://www.jsftutorials.net/defaultActionTag.html
Zane Wlight
Greenhorn

Joined: Aug 07, 2008
Posts: 5
Originally posted by Abiodun Adisa:
Check out

http://www.jsftutorials.net/defaultActionTag.html


Thank you very much Abiodun, it really helps
Srikanth Madasu
Ranch Hand

Joined: Sep 10, 2008
Posts: 48

I think I have a simplest solution.

Use <h:command button value="XXX" action="ssss" type="submit"/>

type=submit attribute will take care of it............

Hope this helps

-Srik


If it's easy.. then everybody would do it!
Enthu Tarun Singh
Greenhorn

Joined: Sep 23, 2013
Posts: 2

Assign id to your submit button and use java script method focus() which will be called at the time of page load. When you are pressing enter key then send that focus to search button. Thats all you have done..
Please let me know if you have done with your requirement..
Thanks


http://www.sitenol.com
Parvathi Raju
Greenhorn

Joined: Aug 04, 2013
Posts: 9
There are 2 solutions.

1)you can use 2 separate forms for button

2)Use command button for which action you want to fire when pressing enter key ,and use command link for another action.by default comman button action is fired when you are pressing enter key
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to specify default button in JSF