且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JSF-受管Bean字段未在PostConstruct上初始化

更新时间:2023-10-06 07:58:28

我认为您正在尝试将bean用作后备bean,并且我想您在jspx <h:outputText binding="#{myBean.outputText}" />中有此标记,所以您需要始终实例化此变量,容器不会为此组件注入任何实例,可以在使用它之前从构造函数或在postconstruct方法中进行初始化.

I think you're trying to use your bean as a backing bean, and I suppose you have this tag in your jspx <h:outputText binding="#{myBean.outputText}" /> well you need to always instantiate this variable the container doesn't inject any instance for this component, you could init from the constructor or in the postconstruct method before you used it.

@PostConstruct
public void testMethod(){
   outputText = new HtmlOutputText();
   getOutputText().setValue(displayText);
}