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

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...