Injecting Managed beans in JSF 2.0
2015-08-27 00:18
621 查看
In JSF 2.0, a new
Let see a
In this example, it uses the
Note
To make this injection successful, the inject property (messageBean) must provide the setter method.
@ManagedPropertyannotation is used to dependency injection (DI) a managed bean into the property of another managed bean.
Let see a
@ManagedPropertyexample :
MessageBean.java – A managed bean named “message“.
import java.io.Serializable; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; @ManagedBean(name="message") @SessionScoped public class MessageBean implements Serializable { //business logic and whatever methods... }
HelloBean.java – Inject the “message” bean into the “messageBean” property.
import java.io.Serializable; import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedProperty; import javax.faces.bean.SessionScoped; @ManagedBean @SessionScoped public class HelloBean implements Serializable { @ManagedProperty(value="#{message}") private MessageBean messageBean; //must povide the setter method public void setMessageBean(MessageBean messageBean) { this.messageBean = messageBean; } //... }
In this example, it uses the
@ManagedPropertyannotation to DI the “message” bean (
MessageBean.java) into the property (
messageBean) of the “
hello” bean (
HelloBean.java) via setter method,
setMessageBean().
Note
To make this injection successful, the inject property (messageBean) must provide the setter method.
相关文章推荐
- Configure Managed Beans in JSF 2.0
- Resources (library) in JSF 2.0
- js获取url请求参数
- JSF 2.0 + Ajax hello world example
- javascript实现自动输出文本(打字特效)
- JS实现自动切换文字的导航效果代码
- javascript引用类型之时间Date和数组Array
- JavaScript实现带箭头标识的多级下拉菜单效果
- javascript 动态修改css样式方法汇总(四种方法)
- js实现向右横向滑出的二级菜单效果
- js实现的早期滑动门菜单效果代码
- js实现仿京东2级菜单效果(带延时功能)
- javascript实现图片延迟加载方法汇总(三种方法)
- js+div实现文字滚动和图片切换效果代码
- js实现div拖动动画运行轨迹效果代码分享
- javascript中判断json的方法总结
- JavaScript中的Function函数
- JavaScript实现非常简单实用的下拉菜单效果
- angular.js双向数据绑定实现动画特效
- JSR-303规范和Hibernate validation