• Post Reply Bookmark Topic Watch Topic
  • New Topic

call a action method with h:commandButton  RSS feed

 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Amir Iqbal
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in my opinion we need a form to perform action. if you do not mention the form then it will not work.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amir,

That is exactly my question :

Why I need a form to perform action ?

Regards
M
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks fro your help.
M
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!