Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bean constructor

 
Zein Nunna
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I have a slight problem
I have a bean, session scope with two methods I call

From the UI (web front end) if I click one button i want a certain method to be called, otherwise a different method.

The issue is that the constrcutor is called each time, which resets some values,
does anybody know of a work around?
How could i possibly tackle this issue?
Is it possible for me to examine which button is has requested the method, so I could direct the requested to the relevant method?

Thanks for your thoughts
Regards
Zein
 
A. Dusi
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your web page code and the bean.
Do you have any bean variables being referred on the page?
It is possible that this session bean is being called the first time when you hit that button. So the constructor gets called.
Add a variable to this bean and use that in the web page in some way(give style hidden if you do not want to be displayed). This way, the constrcutor will be called before the web page is displayed in order to 'get' the new variable. Now when you hit the button, the constructors should not be called since the bean is already initialized by this time.

But I would like to see the code to understand the exact problem.
 
Tim Holloway
Saloon Keeper
Posts: 18303
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something's wrong here. If you declare a bean with session scope, it's constructed when originally referenced, then stored until the session is destroyed - either because it was explicitly invalidated or because it timed out. A constructor can ONLY be called when the bean is first constructed, so what you're describing sounds more like a bean with request scope.
 
Zein Nunna
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there guys,

Sorry for the delay in reply.

Sill mistake, faces-config.xml was set as request... took a while, it's sorted now thanks.

Regards
Zein
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic