Search code examples
jsfprimefacesmanaged-bean

Calling one bean from another bean and setting the value to the bean and display from another bean


I have a dialog which is backed by a managed bean @RequestScoped 'A'. And I am calling the dialog from another bean 'B' also @RequestScoped. So I am using @ManagedProperty for calling 'A' from 'B'. I have set the values(object,variable,etc..) of 'A' from 'B' for display which will depend on an object of 'B'. All the values are set correctly but when the dialog opens, the values I set for 'A' are not displayed.

How to achieve this goal ??

I mean calling a dialog backed by one bean and setting the values of backed bean from another bean ??

I have used a button which is on a p:dataTable row :

<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>

The dialog is displayed but values are not displayed.

Code snippet for '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);
}

Solution

  • I just added update=":receiptViewForm" in the p:commandButton, which is the form id of the dialog.

    <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>
    

    And it just worked.