开发者

JSF 2.0 Primefaces close a dialog in a composite component

开发者 https://www.devze.com 2023-03-19 17:14 出处:网络
I want to display a composite component inside a dialog. It works but then how do I close that dialog from the composite component.

I want to display a composite component inside a dialog. It works but then how do I close that dialog from the composite component.

<p:commandButton value="Display Data Value Assertion Dialog" onclick="dlg2.show();" type="button"/> 
<p:dialog header="Modal Dialog" widgetVar="dlg2" modal="true" height="600" width="800">  
        <tcmt:DataValueAssertion managedBean="#{dataValueAssertionController}"/>
</p:dialog>

In my composite component:

        <h:commandButton val开发者_开发百科ue="Save Assertions">
            <f:ajax listener="#{datatypeAssertionController.saveDatatypeAssertion}"></f:ajax>
        </h:commandButton>

        <h:commandLink value="Close">
            <f:ajax listener="#{datatypeAssertionController.closeDatatypeAssertion}"></f:ajax>
        </h:commandLink> 

When clicking on Save, I want to be able to save the data and close the dialog. When clicking on Cancel, I just want to close the dialog without saving. Both saveDatatypeAssertion and closeDatatypeAssertion methods are placeholders. I need to find a way to get a reference for the dialog dlg2 and then call the hide() method on it.


If you are using JSF 2.0.You can do like this:

 <h:commandButton value="Save Assertions"  >
  <f:ajax event="click" onevent="dlg2.hide()" listener="#{datatypeAssertionController.saveDatatypeAssertion}" />
 </h:commandButton>

<h:commandLink value="Close" >
      <f:ajax event="click" onevent="dlg2.hide()"  listener="#{datatypeAssertionController.closeDatatypeAssertion}" />
</h:commandLink> 
0

精彩评论

暂无评论...
验证码 换一张
取 消