2013-10-25 40 views
1

我有一個對話框和一個顯示此對話框的CommandLink。在此對話框中,我顯示了在命令鏈接的操作(或propertyListener)期間創建的值。但由於更新是在動作之前執行的,因此未設置變量。primefaces:在commandlink更新之前執行動作

<p:commandLink update="@form:myDialog" action="#{myBean.setText('text')}" 
oncomplete="myDialog.show()"> 
</p:commandLink> 
.... 
<p:dialog widgetVar="myDialog" modal="true"> 
     <p:inputText value="#{myBean.text}" /> 
</p:dialog> 

是否可以在更新完成之前執行操作?

+0

請發佈堆棧跟蹤。 – user1983983

+0

我改變了描述。沒有例外,也沒有堆棧跟蹤。 – jobe

回答

1

我對話會更新你沒有指定對話框

<p:commandLink update="myDialog" action="#{myBean.setText('text')}" 
    oncomplete="myDialog.show()"> 
</p:commandLink> 

<p:dialog Id="myDialog" widgetVar="myDialog" modal="true"> 
    <p:inputText value="#{myBean.text}" /> 
</p:dialog> 

的Id屬性這將幫助你。

,但我更喜歡的是使用一個outputpanel

<p:commandLink update="myDialogPanel " actionlistner="#{myBean.setText('text')}" 
    oncomplete="myDialog.show()"> 
</p:commandLink> 

<p:dialog Id="myDialog" widgetVar="myDialog" modal="true"> 
    <p:outputPanel Id=myDialogPanel > 
    <p:inputText value="#{myBean.text}" /> 
    </p:outputPanel> 
</p:dialog> 

,或者你可以更新從managedBean對話框並顯示對話框。如果在managedBean方法中出現任何錯誤,您的對話框將不會顯示,這很有幫助。

RequestContext.getCurrentInstance().update("myDialogPanel"); 
RequestContext.getCurrentInstance().execute("myDialog.show();"); 
1

您可以從ManagedBean本身打開對話框。

RequestContext.getCurrentInstance().execute(myDialog.show()); 

RequestContext可用於從ManagedBean執行任何JavaScript。
您也可以使用RequestContextUpdate 方法更新Managed Bean中的組件。

RequestContext.getCurrentInstance().update("COMPONENT_ID"); 
相關問題