两种方式:
- 使bean请求成为作用域,然后将视图合并为另一个
@ManagedProperty
。
@ManagedBean @RequestScoped public class RequestBean { @ManagedProperty(value="#{param.id}") private Integer id; @ManagedProperty(value="#{viewBean}") private ViewBean viewBean; }视图范围的bean在
@PostConstruct请求范围的bean
期间和操作方法中可用。您只需要记住,在
id不带参数的情况下回发到同一视图时,可能会丢失。
- 或者,在bean初始化期间从请求参数映射中手动获取它。
@ManagedBean @ViewScoped public class ViewBean { private Integer id; @PostConstruct public void init() { id = Integer.valueOf(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id")); } }这样
id,在整个视图范围内都可以使用首字母缩写。



