JSF 1.2-PostConstruct是否在吸气剂之前或之后执行 [英] JSF 1.2 - Does PostConstruct execute before or after getters
问题描述
我有一个支持bean的代码:
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;
}
带有 @PostConstruct 指令的 refreshData()方法是否在所有getter方法之后或之前执行?我之所以这样问,是因为我注意到 getRender()方法始终返回零,即使 getPages()返回例如10的数字.
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.
推荐答案
我不知道您所说的在所有getter方法之前"是什么意思.至少在构造 Bean和设置所有托管属性(在faces-config.xml
中定义的Bean属性)之后立即调用@PostConstruct
.
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
).
因此大致来说:
- Bean被构造.
- 已设置托管属性.
- @PostConstruct被调用.
- Bean进入了JSF生命周期.
您的问题很可能是其他值覆盖了该值.只需运行调试器或让专家检查您的代码即可.
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.
这篇关于JSF 1.2-PostConstruct是否在吸气剂之前或之后执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!