@ManagedProperty with request parameter not set in a @Named bean

﹥>﹥吖頭↗ 提交于 2019-11-30 20:41:47
BalusC

The JSF-specific @ManagedProperty annotation works only in JSF managed beans, not in CDI managed beans. In other words, it works only in classes annotated with JSF-specific @ManagedBean annotation, not in classes annotated with CDI-specific @Named annotation.

CDI does not offer an annotation out the box to inject specifically a HTTP request parameter. JSF utility library OmniFaces offers a @Param annotation for the very purpose of injecting a HTTP request parameter in a CDI managed bean.

@Inject @Param
private String key;

@Inject @Param
private Long id;

Alternatively, use the <f:viewParam> tag in the view.

<f:metadata>
    <f:viewParam name="key" value="#{bean.key}" />
    <f:viewParam name="id" value="#{bean.id}" />
</f:metadata>

See also

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!