Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
662 views
in Technique[技术] by (71.8m points)

testing - JSF 1.2 - Does PostConstruct execute before or after getters

I have this code for a backing bean:

@PostConstruct
 public void refreshData()
 {
  rows  = (int) dd.getRows();
  pages = dd.getPages();
  getRender();
 }

// action
 public void getCount(String sql, Object... values)
  throws Exception
 {
  dd.getCount(sql, values);
  rows  = (int) dd.getRows();
  pages = dd.getPages();
 }

 // getter methods
    public boolean getRender() {
        System.out.println("pages: "+pages);
     boolean rendered = pages > 0? true: false;
     return rendered;
    } 

 public int getRows() {
  return rows;
 }
    public int getPages() {       
     return pages;
    }

Does the refreshData() method with the @PostConstruct directive get executed after or before all the getter methods? I ask this because I notice the getRender() method always return zero even though the getPages() returns a number like 10 for example.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have no idea what you mean with "before all the getter methods". At least the @PostConstruct is called immediately after the construction of the bean and the setting of all managed properties (the bean properties which are definied in faces-config.xml).

Thus roughly:

  1. Bean is constructed.
  2. Managed properties are set.
  3. @PostConstruct is called.
  4. Bean is brought in JSF lifecycle.

Your problem is likely that the value is been overriden by something else. Just run the debugger or have your code reviewed by an expert.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...