如何在 JSF2 中将一个 @Named bean 注入到另一个 @Named bean 中?
我有以下代码:
@Named
@RequestScoped
public class SearchBean{
private String title;
private String author;
// .... getters and setter s
}
在 search.xhtml
中,我有:
<h:inputText value="#{searchBean.title}" />
<h:commandButton action=#{srchUI.action}"/>
我还有以下 ControllerBean:
@Named("srchUI")
@RequestScoped
public class SearchUIController {
public String action(){
// ...
}
}
我想访问 action() 中的
方法...怎么做?如何将此 bean 注入到我的 UI 控制器中?SearchBean.title
I have the following code:
@Named
@RequestScoped
public class SearchBean{
private String title;
private String author;
// .... getters and setter s
}
In search.xhtml
I have:
<h:inputText value="#{searchBean.title}" />
<h:commandButton action=#{srchUI.action}"/>
And I have also the following ControllerBean:
@Named("srchUI")
@RequestScoped
public class SearchUIController {
public String action(){
// ...
}
}
I want to access the SearchBean.title
in action()
method... how to do it? How to inject this bean in my UI Controller?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用@Inject。
Use
@Inject
.getter-setter 是必要的。
Getters-setters are necessary.
使用 @Inject 并在注入的 bean 上添加 Get 和 Set 方法!
Use @Inject and add Get and Set methods on your injected bean!