【问题标题】:Dialogs not showing correctly using modal=true and appendToBody=true使用 modal=true 和 appendToBody=true 时对话框未正确显示
【发布时间】:2013-02-04 12:17:17
【问题描述】:

我阅读了很多关于这个问题的帖子,但找不到解决方案。

我的 JSF 开头有一个带有命令按钮的表单,它应该会打开对话框。 Dialog 在 Dialog 内部有一个表单,以及属性 modal 和 appendToBody。我的页面只是自行重新加载,不会弹出对话框。

<ui:composition template="../templates/site.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:sec="http://www.springframework.org/security/tags">

    <ui:define name="content">
         <h:form>
                   <p:commandButton value="Button" id="myButton" onclick="myDialog.show()" />
        </h:form>

        <p:dialog id="dialog" widgetVar="myDialog"
                        header="Dialog" closable="true" resizable="false" width="600"
                        height="350" modal="true" appendToBody="true" dynamic="true">
                        <h:form>
                           ...
                        </h:form>
        </p:dialog>
    </ui:define>
</ui:composition>

【问题讨论】:

  • 你能不能再发commandButton代码,看起来像科学怪人。
  • 另外发布一些代码,也许你有一些嵌套的form标签...
  • 是的,对不起。我已经编辑了我的命令按钮。嗯,有两种形式,一种在命令按钮外,一种在对话框内,还有 ui:define 和 ui:composition 外

标签: forms jsf dialog primefaces modal-dialog


【解决方案1】:

将您的 commandButton 代码更改为:

<p:commandButton value="Button" type="button" id="myButton" onclick="myDialog.show()"/>

这将创建一个普通的按钮(它只调用 JavaScript)并且不对服务器执行任何 AJAX 或非 AJAX 请求。默认按钮类型为submit

【讨论】:

    猜你喜欢
    • 2011-09-18
    • 1970-01-01
    • 2013-02-08
    • 2013-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多