aspose file tools*
The moose likes JSF and the fly likes Bean constructor 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 "Bean constructor" Watch "Bean constructor" New topic
Author

Bean constructor

Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245
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

Joined: Sep 27, 2004
Posts: 114
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

Joined: Jun 25, 2001
Posts: 16145
    
  21

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.


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

Joined: Mar 31, 2005
Posts: 245
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
 
jQuery in Action, 2nd edition
 
subject: Bean constructor