General JSF question about contructor calls
[Logo]
ICEsoft.org Forums: ICEfaces, ICEmobile, ICEpdf
[Search] Search   [Recent Topics] Recent Topics   [Groups] Home Page | www.icefaces.org  [Register] Register  [Login] Login 
General JSF question about contructor calls  XML
Forum Index -> General Help
Author Message
drewh

Joined: 01/07/2009 00:00:00
Messages: 54
Offline


Hey guys I currently have an application that use tabs to separate the main parts. Basically they are almost entirely different programs but they share some things. Right now I'm using the faces utils get the managed bean so I can pass all the information from one to the other.

What would really help me is if the constructor for the 2nd tab was only called when that tab was in focus. I can then initialize all my values and query the database every time the current tab was opened. Right now the constructor just initializes on page load and they never get called again. Is there a way to call the constructor every time the tab is focused? Thanks for any help.
radu.jakab

Joined: 31/10/2007 00:00:00
Messages: 240
Offline


Hi drewh,

What I suggest you do instead is to move the code out of your constructor (which is generally bad coding anyway), and put it into an initialize method of some sort.
Then you would call this method from a listener when the tab is changed.

Regards,
Radu
drewh

Joined: 01/07/2009 00:00:00
Messages: 54
Offline


So you recommend instead of doing something like this:

Code:
  
  WrapSpecEditor wrapSpecEditor = (WrapSpecEditor) FacesUtils.getManagedBean("WrapSpecEditor"); //at the top of the page
 
 //tab change function
   int wrap_spec_id = wrapSpecList.get(event.getRow()).getWrap_spec_id();
         double benchmark = wrapSpecList.get(event.getRow()).getBenchmark();
         int revolutions_benchmark = wrapSpecList.get(event.getRow()).getRevolutions_benchmark();
         double lower_limit =  wrapSpecList.get(event.getRow()).getLower_limit();
         double upper_limit  =  wrapSpecList.get(event.getRow()).getUpper_limit();
         double price = wrapSpecList.get(event.getRow()).getPrice();
         String description = wrapSpecList.get(event.getRow()).getDescription();
         String shortname = wrapSpecList.get(event.getRow()).getShortname();
         int film_spec_id = wrapSpecList.get(event.getRow()).getFilm_spec_id();
 
         WrapSpec wrapSpec = new WrapSpec(wrap_spec_id, benchmark, revolutions_benchmark, upper_limit, lower_limit, price, description, shortname, film_spec_id);
         WrapSpec wrapSpecCopy = new WrapSpec(wrap_spec_id, benchmark, revolutions_benchmark, upper_limit, lower_limit, price, description, shortname, film_spec_id);
 
         wrapSpecEditor.setWrapSpec(wrapSpec);
         wrapSpecEditor.setWrapSpecDefault(wrapSpecCopy);
 
 
         wrapSpecEditor.setBenchmarkChanged(false);
         wrapSpecEditor.setRevolutionsChanged(false);
         wrapSpecEditor.setLowerLimitChanged(false);
         wrapSpecEditor.setUpperLimitChanged(false);
         wrapSpecEditor.setDescriptionChanged(false);
         wrapSpecEditor.setDateChanged(false);
 
         PkgLoadDate pkg = new PkgLoadDate(wrapSpecList.get(event.getRow()).getWrap_spec_id());
 
         wrapSpecEditor.setDate(pkg.getDate());
         wrapSpecEditor.setDateCopy(pkg.getDate());
         wrapSpecEditor.setNewDate(pkg.getDate());
 
         wrapSpecEditor.setSubmitDisabled(true);
         wrapSpecEditor.setDefaultsRendered(false);     
 



do something like this:
Code:
 
 wrapSpecEditor.setWrapSpecId(wrap_spec_id);
 wrapSpecEditor.initialize();
 
 
 or even just
 
 wrapSpecEditor.initalize(wrap_spec_id);
 


And then have all the initialize code for the page in the initialize function for the wrapspeceditor bean.
I'm not sure why I didn't think of that before. Haha.
 
Forum Index -> General Help
Go to:   
Powered by JForum 2.1.7ice © JForum Team