开发者

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 th开发者_如何学JAVAe getPages() returns a number like 10 for example.


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.


The JSF 1.2 spec says specifically (Page 11, Item 119 preface):

Methods on managed beans declared to be in request, session, or application scope, annotated with @PostConstruct, must be called by the JSF implementation after resource injection is performed (if any) but before the bean is placed into scope.

(More details in the spec.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜