JSF 1.2 - Does PostConstruct execute before or after getters

后端 未结 2 1573
[愿得一人]
[愿得一人] 2020-12-18 12:08

I have this code for a backing bean:

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

/         


        
相关标签:
2条回答
  • 2020-12-18 12:51

    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 讨论(0)
  • 2020-12-18 13:03

    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.

    0 讨论(0)
提交回复
热议问题