It's not a secret anymore!
The moose likes JSF and the fly likes call a action method with h:commandButton Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "call a action method with h:commandButton" Watch "call a action method with h:commandButton" New topic
Author

call a action method with h:commandButton

Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 912
Hi

I have a simple problem, I try to call a bean action with a h:commandButton
the code looks like :



but this is not working - but if I add the button in to a fromular then it works, after this the code looks like :




My question is why do I need to use a form ?

Regards,
M


SCJP, SCJD, SCWCD
Amir Iqbal
Ranch Hand

Joined: Jun 23, 2007
Posts: 97
in my opinion we need a form to perform action. if you do not mention the form then it will not work.


i am Java +ve Now !
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 912
Hi Amir,

That is exactly my question :

Why I need a form to perform action ?

Regards
M
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 14480
    
    7

Because the commandButton builds on the HTML Submit button object and HTML submits can only be done in conjunction with an HTML Form object that contains it. That's specified by the RFCs that define HTML and the HTTP protocol.

As a secondary reason, JSF doesn't simply fire off an event - there's a whole lot of extra information that goes down to the server as well, so a full-blown POST request has to be made.


Customer surveys are for companies who didn't pay proper attention to begin with.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Webbrowsers only understand HTML.
JSF just renders HTML (alongside some other client side stuff like JS/CSS).
Open a JSF page in your favourite browser and view source. Do you see?

Well, to understand what JSF renders, you need to understand HTML. If you are new to HTML as well, I highly recommend you to go through this tutorial: http://www.w3schools.com/html/ Forms are covered here: http://www.w3schools.com/html/html_forms.asp
[ December 15, 2008: Message edited by: Bauke Scholtz ]

Code depot of a Java EE / JSF developer | JSF / Eclipse / Tomcat kickoff tutorial | DAO kickoff tutorial | I ♥ Unicode
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 912
Thanks fro your help.
M
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
You're welcome.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: call a action method with h:commandButton
 
Similar Threads
JSF bean methods
JSF selectOneMenu + Database Values
Submit dataTable fields
How to succesfully replace 4 components with 7? :)
JavaScript form submit fails in IE7, works in FF and Safari