2015-02-24 99 views
0

我有一個託管bean支持的對話框@RequestScoped'A'。我從另一個豆'B'也調用對話@RequestScoped。所以我使用@ManagedProperty'B'呼叫'A'。我已經設置了'A'的值(對象,變量等)從'B'進行顯示,這取決於'B'的一個對象。所有的值都設置正確,但是當對話框打開時,我爲'A'設置的值不顯示。從另一個bean調用一個bean並將該值設置爲該bean並從另一個bean顯示

如何實現這個目標?

我的意思是調用由一個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); 
} 
+0

不要忘記添加每個屬性獲取和設置。發佈你的java代碼。 – giaffa86 2015-02-24 10:46:56

+0

好的,我發佈了代碼。 – SudeepShakya 2015-02-24 10:50:17

回答

0

我只是在p:commandButton,這是對話的形式加入ID update=":receiptViewForm"

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

而且這只是工作。

0

這裏的問題是,當您嘗試訪問它從B中會丟失的價值。

我建議你定義一個更長的作用域,以便在被B調用時保持它的值(類似於@ViewScoped應該可以工作)。

@ViewScoped 
public class A {} 

@RequestScoped 
public class B { 
    @ManagedProperty(value = "#{a}") 
    private A a; 
} 
+0

好的,我會盡力回覆。 – SudeepShakya 2015-02-25 04:21:05

+0

它沒有工作。 – SudeepShakya 2015-02-25 04:50:54

相關問題