[英]How to share data between two @ViewScoped beans?
I am trying to pass id (long) from one.xhtml to another .xhtml. 我试图将id(long)从one.xhtml传递到另一个.xhtml。 Both the backing beans are @ViewScoped
and I am trying to share long id between them. 这两个支持bean都是@ViewScoped
,我正在尝试在它们之间共享长id。
I am getting error with <f:viewParam/>
我在<f:viewParam/>
时出错
com.sun.faces.mgbean.ManagedBeanCreationException
: Unable to create managed bean saleOrder.com.sun.faces.mgbean.ManagedBeanCreationException
:无法创建托管bean saleOrder。 The following problems were found: - The scope of the object referenced by expression#{param.foo}
, request, is shorter than the referring managed beans (saleOrder
) scope of view. 发现了以下问题:-由表达式#{param.foo}
(请求)引用的对象的范围比引用的托管Bean(saleOrder
)的视图范围要短。
I am have following code. 我有以下代码。
@ManagedBean
public class InvoiceView{
private long number;
// setter getter.
}
@ManagedBean
@ViewScoped
public SearchInvoice{
private List<InvoiceView> views;
private InvoiceView selectedView; // this is coming from <p:dataTable>
}
@ManagedBean
@ViewScoped
public class SaleOrder {
@ManagedProperty("#{param.foo}")
private String number;
@PostConstruct
public void init(){
//sysout number;
}
}
I have following code in searchInvoice.xhtml
file. 我在searchInvoice.xhtml
文件中有以下代码。
<!-- I have not desclared <f:metadata/> -->
<h:commandButton value="Place Sale Order"
action="#{searchInvoice.forwardToSaleOrder}" <!-- this return saleOrder.xhtml string -->
rendered="#{not empty searchInvoice.views}">
<f:viewParam name="foo" value="#{searchInvoice.selectedView.number}" />
</h:commandButton>
You can use <f:viewParam>
(JSF 2) in saleOrder.xhtml, which works with view scoped beans. 您可以在saleOrder.xhtml中使用<f:viewParam>
(JSF 2),该功能可用于视图作用域的bean。 Check out this article . 查看这篇文章 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.