本文介绍了@ManagedProperty 在 @PostConstruct 之后注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题已在 MYFACES 2.1 实现中解决

THIS PROBLEM IS ALREADY SOLVED IN THE MYFACES 2.1 IMPLEMENTATION

我有一个链接,可以像这样正确传递整数参数:

I have a link which passes an Integer parameter properly like this:

<h:link outcome="/process/createProcess">
    <f:param name="id" value="#{process.idprocess}" />
    Edit
</h:link>

它正确转到createProcess.xhtml?id=21",并且我在请求范围支持Bean createProcess中有此代码:

It goes to "createProcess.xhtml?id=21" properly, and I have this code in the request scope backing Bean createProcess:

@ManagedProperty(value="#{param.id}")
private Integer idProcess;

private Process newProcess;

@PostConstruct
public void init()
{
    log();
    if (idProcess!=null)
        newProcess = Dao.getProcessDAO().get(idProcess);
    else
        newProcess = new Process();
}

我注意到 idProcess 始终为空.调试后我意识到 setIdProcess 方法被称为 AFTER @PostConstruct.

I've notice that idProcess is always null. After debugging I realized that setIdProcess method is called AFTER @PostConstruct.

我知道注入是在构建 bean 之后完成的,并且所有 managedProperties 都在 @PostConstruct 中可用.

I understand that injection is done just after the construction of the bean and all the managedProperties are available in @PostConstruct.

我错过了什么?

推荐答案

仅供参考,我觉得这个帖子的问题是MYFACES-3116,with已经固定在,所以2.0.6、2.1.0及以上版本没有.

Just for reference, I think the issue in this post is MYFACES-3116, with was already fixed at , so 2.0.6, 2.1.0 and upper versions does not have it.

这篇关于@ManagedProperty 在 @PostConstruct 之后注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 08:37