• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to access a method in JSF with session scope via hyperlink

 
tanveer hyd
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a hyperlink say,

http://xxx.xxx.xxx.xxx:8080/my-project/faces/module/details.xhtml?code=ABCFVG12354

now, i want to access a managed bean's method to execute a service call related to the code embedded in the hyperlink.

My Managed bean

@ManagedBean(name="details")
@SessionScoped
public class XXXX extends Bean implements Serializable{

public XXXX(){...... }
public myMethod(..){
service.getDataRelatedToHyperlinkCode(....passing code here to fetch details from DB)
}

}

if i use postConstruct annotation it is getting executed only once since it is a session scope. and point to be noted is i cannot use viewscope and requestscope.

please suggest some solution.

thanks
 
Tim Holloway
Bartender
Posts: 18412
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I see "cannot use XXX" in a question without a specific reason, my immediate thought is "Mananagement is an Idiot".

There's a reason why most features exist, even if some people are too "clever" to understand them.

Now, from a technical point of view, Request scope is almost always useless in JSF because it can't manage postback state. And View scope is only applicable when the data is all on the same View. And, if you are one of those unfortunates still stuck with JSF version 1, you're excused, although JSF2 has been around long enough that you should seriously consider converting, as at the moment, the upgrade is cheap, but not likely to stay that way forever.

I don't usually use @PostConstruct, and your problem is one reason why. When I need data fetched from a database (or other external source(s)) before the first display of a View in a workflow, I generally have a method in the bean that the preceeding View can invoke from the action method that navigates me to the new View. That works well with session-scoped beans, since they can be injected into the preceding View's backing bean. It doesn't work, of course, with View scope, since you'll be changing to a new View, but then again, you've been forbidden to use View scope anyway.
 
tanveer hyd
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your reply, i have solved this problem by using

<f:event type="preRenderView" listener="#{..}"/>

I was not aware of this tag in jsf..

thanks,
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!