• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help Required

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using a sessionScoped JSF Managed Bean. Now, I want to call a method every time that bean is called. If I put the method in the SessionScoped Managed Bean then that method will be called only once as long as the session is there.

Can anyone help me about where should I put the method code so that every time that Session Bean is called, the method gets executed? This method gets some value from database.

Although, RequestScope bean will solve my purpose of calling that method every time the bean is called, but I lose some of the values like primary key which I am not using to set anywhere and also the variables in RequestScope bean will be reset, which I don't want.

I hope I am able to explain my problem clearly.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You get better results and get them faster if you make your question topic reflect what you want to know. A lot of people only look at the message summaries, and a generic "Help required" topic doesn't tell them that there's anything of interest in your question.

It helps sometimes to be nit-picky about terms: You don't "call" a bean. You reference properties in a bean, and you invoke methods in a bean. The bean itself is just a container and does nothing.

So there are a number of things you might actually want when you say you want to "call a method every time that bean is called". You could be referring to property read/write operations, you could be referring to method invocations, or both. In JSF, since you don't have direct public access to the properties, that means that at least 3 different kinds of methods (4, including constructor) that could be looked at: property accessors (set/get), action processors, and event listeners. It would help if you could narrow that down.
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What kind of method are you calling on the backing bean? And how are you calling the backing bean from the JSF?
To call the bean :MyBean, let's say you have to use this line in your JSF page:

This will call the getter/setter of the method getProp1() in MyBean.java - everytime you make that reference.
You can also use this:

That will also call the setProp1() in the MyBean.java, everytime you make that reference.

Now, if you want to call a separate method, say beanMethod() everytime you make a reference to the myBean from your JSF page in one way or the other, then I think this is what you should do:
Separate the variables(V) which should not be changed (into an application scoped bean(B1)) and the method(M) which needs to be called everytime in the constructor of a request scoped bean(B2). Then use the B2 as the backing bean of your JSF page.
 
Tim Holloway
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tina Ma wrote:
To call the bean :MyBean, let's say you have to use this line in your JSF page:





That wasn't "calling" a bean. You can tell because the bean name has a property name attached to it. You're calling the property's accessors for that bean.
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See what I mean Tim?
 
Tina Ma
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
technicality duly noted guys.
 
Tim Holloway
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No mere annoyingly pedantic human can ever be a match for a computer when it comes to insisting on knowing trivial distinctions.
 
reply
    Bookmark Topic Watch Topic
  • New Topic