从另一个 bean 调用一个 bean 并将值设置为 bean 并从另一个 bean 显示
Calling one bean from another bean and setting the value to the bean and display from another bean
我有一个由托管 bean @RequestScoped
'A'
支持的对话框。我正在从另一个 bean 'B'
也 @RequestScoped
调用对话框。所以我使用 @ManagedProperty
从 'B'
调用 'A'
。我已经从 'B'
设置了 'A'
的值(对象、变量等)用于显示,这将取决于 'B'
的对象。所有值都设置正确,但当对话框打开时,我为 'A'
设置的值不会显示。
如何实现这个目标??
我的意思是调用一个由一个 bean 支持的对话框并从另一个 bean 设置支持的 bean 的值??
我使用了 p:dataTable
行上的按钮 :
<p:column headerText="Actions">
<p:commandButton icon="ui-icon-search" title="View"
process="@this"
oncomplete="receiptViewWidget.show()"
action="#{receiptRepoMB.forReceiptDialog}">
<f:setPropertyActionListener
target="#{receiptRepoMB.receiptDetObj}" value="#{rd}" />
</p:commandButton>
</p:column>
显示对话框但不显示值。
'B'
的代码段:
@ManagedProperty(value = "#{receiptMB}")
private ReceiptMB receiptMB;
public ReceiptMB getReceiptMB() {
return receiptMB;
}
public void setReceiptMB(ReceiptMB receiptMB) {
this.receiptMB = receiptMB;
}
public void forReceiptDialog(){
ReceiptModel receiptObj = receiptDetObj.getReceiptModel();
receiptMB.setReceiptSummary(receiptObj);
}
这里的问题是当您尝试访问它时,从 B 使用的 A 的值将会丢失。
我建议你用更长的范围定义 A 以在被 B 调用时保持其值。(@ViewScoped 之类的东西应该可以工作)。
@ViewScoped
public class A {}
@RequestScoped
public class B {
@ManagedProperty(value = "#{a}")
private A a;
}
我刚刚在 p:commandButton
中添加了 update=":receiptViewForm"
,这是对话框的表单 ID。
<p:commandButton icon="ui-icon-search" title="View"
process="@this" oncomplete="receiptViewWidget.show()"
action="#{receiptRepoMB.forReceiptDialog}"
update=":receiptViewForm">
<f:setPropertyActionListener target="#{receiptRepoMB.receiptDetObj}"
value="#{rd}" />
</p:commandButton>
而且效果很好。
我有一个由托管 bean @RequestScoped
'A'
支持的对话框。我正在从另一个 bean 'B'
也 @RequestScoped
调用对话框。所以我使用 @ManagedProperty
从 'B'
调用 'A'
。我已经从 'B'
设置了 'A'
的值(对象、变量等)用于显示,这将取决于 'B'
的对象。所有值都设置正确,但当对话框打开时,我为 'A'
设置的值不会显示。
如何实现这个目标??
我的意思是调用一个由一个 bean 支持的对话框并从另一个 bean 设置支持的 bean 的值??
我使用了 p:dataTable
行上的按钮 :
<p:column headerText="Actions">
<p:commandButton icon="ui-icon-search" title="View"
process="@this"
oncomplete="receiptViewWidget.show()"
action="#{receiptRepoMB.forReceiptDialog}">
<f:setPropertyActionListener
target="#{receiptRepoMB.receiptDetObj}" value="#{rd}" />
</p:commandButton>
</p:column>
显示对话框但不显示值。
'B'
的代码段:
@ManagedProperty(value = "#{receiptMB}")
private ReceiptMB receiptMB;
public ReceiptMB getReceiptMB() {
return receiptMB;
}
public void setReceiptMB(ReceiptMB receiptMB) {
this.receiptMB = receiptMB;
}
public void forReceiptDialog(){
ReceiptModel receiptObj = receiptDetObj.getReceiptModel();
receiptMB.setReceiptSummary(receiptObj);
}
这里的问题是当您尝试访问它时,从 B 使用的 A 的值将会丢失。
我建议你用更长的范围定义 A 以在被 B 调用时保持其值。(@ViewScoped 之类的东西应该可以工作)。
@ViewScoped
public class A {}
@RequestScoped
public class B {
@ManagedProperty(value = "#{a}")
private A a;
}
我刚刚在 p:commandButton
中添加了 update=":receiptViewForm"
,这是对话框的表单 ID。
<p:commandButton icon="ui-icon-search" title="View"
process="@this" oncomplete="receiptViewWidget.show()"
action="#{receiptRepoMB.forReceiptDialog}"
update=":receiptViewForm">
<f:setPropertyActionListener target="#{receiptRepoMB.receiptDetObj}"
value="#{rd}" />
</p:commandButton>
而且效果很好。