File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes how to call a method in jsf 2.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "how to call a method in jsf 2.0" Watch "how to call a method in jsf 2.0" New topic
Author

how to call a method in jsf 2.0

raj talatam
Ranch Hand

Joined: Apr 19, 2012
Posts: 87
Hi
i have written simple bean

my xhtml code is



what is wrong with my code , if i execute this is giving correct results

i am not why xhtml page showing error

Thanks
rajendar
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

As per the documentation of h:commandButton the action attribute should be:

The action attribute accepts a method-binding expression for a backing bean action method to invoke when this component is activated by the user. An action method must be a public method with no parameters that returns a String. The returned string represents the logical outcome of the action (eg. "success", "failure", etc. ) and is used by the JavaServer Faces MVC framework to determine which view to display next.


May be you are actually want to write an actionListener which is defined as:

The actionListener attribute accepts a method-binding expression for a backing bean action listener method that will be notified when this component is activated by the user. An action listener method must be a public method with an ActionEvent parameter and a void return type.


Mohamed Sanaulla | My Blog
raj talatam
Ranch Hand

Joined: Apr 19, 2012
Posts: 87
Hi,
i am new to jsf,
i just fallowed the tutorial in youtube.

webpage
the same version of jsf i am using , the difference is he is Using netbeans , i am using eclipse
Thanks
Rajendar


raj talatam
Ranch Hand

Joined: Apr 19, 2012
Posts: 87
Mohamed Sanaulla wrote:As per the documentation of h:commandButton the action attribute should be:

The action attribute accepts a method-binding expression for a backing bean action method to invoke when this component is activated by the user. An action method must be a public method with no parameters that returns a String. The returned string represents the logical outcome of the action (eg. "success", "failure", etc. ) and is used by the JavaServer Faces MVC framework to determine which view to display next.


May be you are actually want to write an actionListener which is defined as:

The actionListener attribute accepts a method-binding expression for a backing bean action listener method that will be notified when this component is activated by the user. An action listener method must be a public method with an ActionEvent parameter and a void return type.

Hi,
i am new to jsf,
i just fallowed the tutorial in youtube.

he haven't got any error what you are quoted but in my scenario i am getting error
the same version of jsf i am using , the difference is he is Using netbeans , i am using eclipse
Thanks
Rajendar
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16137
    
  21

You do not "call a method" from a JSF View. You specify a method in EL and JSF calls the method.

For action methods, this means not this:


But this:


Beyond that, however, the action method is used when you submit an entire page form. For AJAX-based submit actions, you have to designate an actionListener on the f:ajax tag.

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

Joined: Apr 19, 2012
Posts: 87
Tim Holloway wrote:You do not "call a method" from a JSF View. You specify a method in EL and JSF calls the method.

For action methods, this means not this:


But this:


Beyond that, however, the action method is used when you submit an entire page form. For AJAX-based submit actions, you have to designate an actionListener on the f:ajax tag.

hi tim,
if you see that video, to call an action method he put, #{user.check()} , same thing i fallowed in eclipse i am getting errors,
i am not able to understand what went wrong, is that tutorial is wrong o what
2)

the same thing i observed , if i kept ajax tag also , the page is submitting entirely, as like what you explained but in this tutorial, he shown ajax based behaviour in that chrome browser(tutorial 5)

please explain me , what is best way to learn jsf, as of now i am fallowing youtube tutorials and same thing when i am practicing i am getting these kind of doubts, suggest me best approach or is there any problem with the jsf version i am using i am sure he also used 2.0 .
thanks
raj
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16137
    
  21

Don't believe everything you see on the Internet. Sometimes it's ignorant people propagating their own ignorance. Like, me, for example.

Actually even Oracle recommends certain JSF tactics that I disagree with, but in this particular case, as I said, you need to rid yourself of the idea that a View Template is a logic component and should therefore be "programmed", complete with "method calls". The View Template is data and its primary purpose is to provide the UI specifications for the View.

I myself am not a person who has a lot of use for video tutorials. I much prefer a good book. In fact, an actual physical book when intensely technical stuff is involved. Unfortunately, the local bookstore has almost completely eliminated inventory of books on JEE and JSF, so I have no idea what's good these days.
Guy deLyonesse
Ranch Hand

Joined: Apr 12, 2011
Posts: 200

Tim Holloway wrote:Unfortunately, the local bookstore has almost completely eliminated inventory of books on JEE and JSF, so I have no idea what's good these days.


They're a bit on the lower level techincally, but the HeadFirst series by O'Reilly are great fun to read and provide a perspective that helps me "get it" more quickly than the more dry style. I recommend them highly to anyone who's newly learning, or who just wants to review old material from a fresh perspective.
raj talatam
Ranch Hand

Joined: Apr 19, 2012
Posts: 87
Tim Holloway wrote:Don't believe everything you see on the Internet. Sometimes it's ignorant people propagating their own ignorance. Like, me, for example.

Actually even Oracle recommends certain JSF tactics that I disagree with, but in this particular case, as I said, you need to rid yourself of the idea that a View Template is a logic component and should therefore be "programmed", complete with "method calls". The View Template is data and its primary purpose is to provide the UI specifications for the View.

I myself am not a person who has a lot of use for video tutorials. I much prefer a good book. In fact, an actual physical book when intensely technical stuff is involved. Unfortunately, the local bookstore has almost completely eliminated inventory of books on JEE and JSF, so I have no idea what's good these days.


Hi Tim,
i thought i will close this thread but , what you have said is true in eclipse IDE to call action methods
#{user.check}
, but unfortunately i have changed ide to Netbeans , in that tool tip itself giving
#{user.check()}
, i am afraid by this flaky behavior , i trierd removing this () from method call this scenario also working, can you explain why this is happing
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16137
    
  21

raj talatam wrote:
Hi Tim,
i thought i will close this thread but , what you have said is true in eclipse IDE to call action methods
#{user.check}
, but unfortunately i have changed ide to Netbeans , in that tool tip itself giving
#{user.check()}
, i am afraid by this flaky behavior , i trierd removing this () from method call this scenario also working, can you explain why this is happing


That might explain why people are so insistent on coding it "wrong".

My suspicion is that Netbeans is thinking that you are coding JavaScript. And JavaScript would be using "()".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to call a method in jsf 2.0