【问题标题】:primefaces dialog does not show up on button clickprimefaces 对话框在按钮单击时不显示
【发布时间】:2017-01-24 10:24:36
【问题描述】:

我有 primefaces 版本 6.0,我遇到了对话框未显示的问题。

这是按钮。

<p:commandButton id="newRequestButton"
                 class="btn btn-lg btn-primary" 
                 value="New Request"
                 update=":newRequestForm:newRequestDialog" 
                 oncomplete="PF('newRequest').show()" />

这就是对话框

<p:dialog header="Request Definitions" widgetVar="newRequest"
                  resizable="true" width="600" showEffect="explode"
                  hideEffect="explode" modal="true" height="300" 
                  class="modal-dialog">
    <h:form id='newRequestForm'>
        <h:panelGrid id="newRequestDialog" columns="1" cellpadding="4"        
                     class="modal-content">

        </h:panelGrid>
    </h:form>
</p:dialog>

可能是什么问题。我遵循了几个答案,例如 thisthis 无济于事。

编辑: 相对于forms 和激活它们的commandButtonsdialogs 应该放在哪里?

【问题讨论】:

  • 您在日志记录中调查了什么?浏览器控制台?您是否尝试过更新对话框内容然后显示它而不是更新对话框?
  • @Kukeltje 如您所见,我正在更新包含对话框内容的h:panelGrid
  • 对不起,误读了... :-( 表单应该在对话框中,当它是模态的并且有一个“appendTo”的主体(参见 PF 文档。与 commandButton 相关的位置是不是很相关。没有理由这不应该起作用,除非由于 commandButton 根本不起作用而没有调用服务器,这可以通过用普通的 javascript 警报替换“show”来测试。
  • @Kukeltje 即使appendTo 没有任何反应,为什么“commandButtons”不起作用?
  • 我没有说你应该使用appendTo,我说使用它时,你需要表单在对话框中。为什么 commandButtons 不起作用,好吧.... stackoverflow.com/questions/2118656/…

标签: primefaces


【解决方案1】:

你需要把commandButton和dialog放在h:form标签中,id属性像“form”,然后在commandButton的update属性中,首先写“form”(h:form的id属性值,其中包含按钮和对话框)。试试下面的代码:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
    <h:head>
   </h:head>
    <h:body>
    <h:form id="form">

         <p:commandButton id="newRequestButton"
                 class="btn btn-lg btn-primary" 
                 value="New Request"
                 update=":form:newRequestDialog" 
                 oncomplete="PF('newRequest').show()" />

         <p:dialog header="Request Definitions" widgetVar="newRequest"
                  resizable="true" width="600" showEffect="explode"
                  hideEffect="explode" modal="true" height="300" 
                  class="modal-dialog">

       <p:outputPanel id="newRequestDialog" style="text-align:center;"> 

        <p:panelGrid  columns="1" class="modal-content">

        </p:panelGrid>

       </p:outputPanel>

         </p:dialog> 

        </h:form>
</h:body>
</html>

【讨论】:

  • 我的代码实际上是相似的,但表单没有嵌套。但这仍然行不通。我使用铬。打开开发人员选项,在控制台上我没有收到任何错误消息或点击时根本没有任何消息。
  • 以上代码在 primefaces 5.0 中运行良好
  • 现在试试上面编辑过的代码,它不包含嵌套表单,并且对话框也在点击commandButton时打开
  • 还是同样的问题。
  • 有什么问题?对话框没有打开吗?还是 panelGrid 没有更新??
【解决方案2】:

问题是我同时包含了 bootstrap jquery 和 primefaces 捆绑的 jquery。禁用引导 jquery 有效。

【讨论】:

  • 那么您很可能在 JS 控制台中出现错误...下次请创建一个 minimal reproducible example... 现在没有任何导致您的问题可见。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-05-12
  • 1970-01-01
  • 1970-01-01
  • 2021-03-16
  • 1970-01-01
  • 2013-04-10
  • 2013-04-18
相关资源
最近更新 更多