双射(bijection)
双射(bijection,即 bidirectional injection 的简称)。当注出(outject)属性数据时,视图可以通过名称找到它。在 postback 或者组件初始化时,数据被注入(inject)到一个组件中。后者是著名的控制反转(inversion of control,IOC)模式的一种实现,可用于连接委托对象。
传统 IOC 与 双射之间的主要不同点在于,双射使长期作用域中的组件可以引用短期作用域中的组件。可以进行这种连接是因为双射在调用组件时(而不是启动容器时)解析依赖项。双射是有状态组件开发的基础。
@Name("addressManager")
public class AddressManagerBean{
@DataModel
private List
addresses;
@DataModelSelection
@Out(required=false)
private Address selectedAddress;
@Factory(value="addresses")
public void loadAddress(){
//logic to load addresses into this.addresses
}
public String showDetail(){
//no work needs to be done to prepare the selected address
return "/address.jspx";
}
public String list(){
return "/addresses.jspx";
}
}
--------------------------------
@Name("addressManager")
public class AddresManagerBean{
@In("#{addressService}")
private AddressService addressService;
}
阅读(1109) | 评论(0) | 转发(0) |