• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Where is doGet() in JSF?

 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I access servlet from a link or browswe address , doGet() is executed.
How to code a doGet() in JSF Bean?
Thanks.
 
Rick Beaver
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

All JSF actions work by Post unfortunately - you will have to use a normal anchor etc to do a get...
 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
What is "normal anchor"?
Thanks.
 
Rick Beaver
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I mean you will have to use a normal "a" tag or another standard HTML navigation method.

You can reference a get URL as a src within a JSF component - for an image for example.
 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I meant was that in a servlet doGet() is the entry point where I can retrieve request parameters etc. How to code such a entry point in JSF bean if my JSF is evoked by url instead of POST?
Thanks.
 
Rick Beaver
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I think I see. So you want to set parameters in your bean via a get instead of a post. To be honest I dont think there is an easy way to do this. There may be a way by querying the FacesContext from your bean but your bean would not actually be able to do anything without a method being called on it - which, in JSF, needs to be done by post.

Can you provide the context of the problem and then it may be easier to provide a workable solution for you?
 
Michael Valentino
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Been a little while since I used JSF, but I believe you can access the request parameters from the FacesContext (not sure if that's the correct name or not) object. Check the JSF API for the JSF implementation which you're using. This should work regardless of a GET or POST method.
 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I want to do:

I have a JSF that displays monthly orders. I want to put URL links in regular html page so that each link only gives orders in a particular month:

It seems that bean functions can be associated with JSF tags so that when user clicks submit button these function will be executed.
But how to evoke bean functions when JSF is accessed from URL as shown avove?

Thanks.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


will probably work. I think there's a cleaner way, but I don't recall it. I've learned to avoid using FacesContext where possible, but sometimes it's not possible.
 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim;

In which bean function do we use FacesContext to get values in queryString?
In servlet we have doGet() function. What would be the counterpart of doGet() in JSF?

Thanks.
 
g madhava
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Based on the code below:


you are going to show to the user the "order.jsp" jsp page.
This JSP page needs to interact with the managed bean.
Let's say you are displaying "order.jsp" as a table below.



Now you have the JSF Managed Bean declared as "jsf_mb_OrderDisplayBean" in the faces-config.xml corresponding to the class,let's say "com.javaranch.OrderDisplayBean"

This class has a method that "getOrders()" that will display the list of orders


In this method, you can use the code supplied by "Tim Holloway" or my code as below. The one given by "Tim" returns String[].



You ** DO NOT ** need to implement either the doGet() method or either the doPost() method.
 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks g for the explaination.
I finally got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic