如何以编程方式打开PrimeFaces-Dialog?

时间:2014-12-23 10:43:10

标签: javascript jsf primefaces

我知道有很多关于这个话题的问题,但没有人可以帮助我。

我只想通过托管bean打开一个对话框,因为我需要一个普通的对象来处理,所以我想要一个actionListener,它生成一个新对象,然后打开对话框。

问题:它不起作用。为什么?我不知道。

我在任何控制台都没有收到任何错误。没有JS错误,我的Tomcat-Console中没有任何内容,他的日志中没有任何内容。而且我非常非常确定它应该以这种方式工作。

这是我做的:

“添加”-Button:

<p:outputPanel style="float:right">
<p:commandButton value="Hinzufügen" icon="ui-icon-plusthick"
    actionListener="#{lessonTypeController.addLessonTypeDialog}" />
</p:outputPanel>

actionListener如下所示:

public void addLessonTypeDialog() {

    lessonType = new LessonType();
    lessonType.setTypicalDuration(getTypicalDuration());
    RequestContext context = RequestContext.getCurrentInstance();
    context.execute("PF('addLessonTypeDialog').show()");

}

应该打开的对话框(但不想):

<p:dialog header="Add a lessontype"
    id="addLessonTypeDialog" widgetVar="addLessonTypeDialog"
    minHeight="600" modal="true" draggable="false" resizable="false">
    <p:ajax event="close" update="@form" />
    <p:outputPanel>
        ... Some content which works fine if dialog is called different
    </p:outputPanel>
</p:dialog>

该对话框与调用按钮放在同一个xhtml页面中。

我真的不知道为什么这不起作用。正如我所说的那样,我真的很确定这是正确的。也没有错误。单击按钮时,只是没有一个反应。

其他一切工作正常,我也使用自己的xhtml页面中的对话框,它工作正常,但现在必须重构,因为我需要close-event来更新表单。

如果我通过JS直接调用对话框(就像我在bean中所做的那样,只需要按钮的onlick-event)就可以了,但是我遇到了问题,因为actionListener不够快,无法生成新的对象。 JS已经显示了导致错误和NullPointerExceptions的对话框。

请帮助我,这是一个重要的学校项目我必须独自完成,因为我的队友什么都不做,我真的不知道该怎么办。

2 个答案:

答案 0 :(得分:0)

我知道在以前的某些版本中,如果widgetVar的值与id相同,则会发生奇怪的事情。因此,尝试更改其中一个并查看它是否有效:

context.execute("PF('wAddLessonTypeDialog').show()");

<p:dialog id="addLessonTypeDialog" widgetVar="wAddLessonTypeDialog" ...

引用Primefaces的作者,来自this thread

  

不要给组件ID和widgetVar命名相同。

答案 1 :(得分:0)

配置怎么样?试试checking that your faces-config contains the Dialog Framework Configuration (Page 519 in the Primefaces 5.1 Users Guid, it's easy to miss):

<application>
  <action-listener>
    org.primefaces.application.DialogActionListener
  </action-listener>
  <navigation-handler>
    org.primefaces.application.DialogNavigationHandler
  </navigation-handler>
  <view-handler>
    org.primefaces.application.DialogViewHandler
  </view-handler>
</application>
相关问题