【问题标题】:ADF Faces dialog - dialogListener not triggeringADF Faces 对话框 - dialogListener 未触发
【发布时间】:2015-05-21 08:07:43
【问题描述】:

单击确定按钮时,我的“okCancel”类型对话框不会触发服务器上的任何事件。

取消按钮工作正常,只是隐藏了弹出窗口。

我正在使用 Oracle ADF Faces 12.1.3 和 JBoss seam 2.3 来注入 bean。

这是弹出窗口和对话框代码:

<af:form id="mainForm">
        <af:panelStretchLayout id="psl1">
            <!-- page layout -->
        </af:panelStretchLayout>
        <af:popup id="myPopup"
          binding="#{bkBean.myPopup}"
          contentDelivery="lazyUncached">
          <af:dialog id="myDialog" closeIconVisible="true"
            modal="true" okVisible="true" cancelVisible="true"
            title="Import from server to #{bkBean.file.name}"
            type="okCancel"
            dialogListener="#{bkBean.doSomething}">
            <af:panelFormLayout id="pfl1">
              <!-- Several input text here -->
            </af:panelFormLayout>
          </af:dialog>
      </af:popup>
    </af:form>

这里是 dialogListener 的代码。我在 if 语句中设置了一个调试点:

import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

@Name("exportImportServer")
@Scope(ScopeType.SESSION)
public class ExportImportServerBean implements Cleanable {
    public void importFromServer(DialogEvent event) {
        if (event.getOutcome() == DialogEvent.Outcome.ok) {
        }
    }
}

exportImportServer 支持 bean 在会话范围内。

如果我在 exportImportServer 支持 bean importFromServer 方法内的第一个代码行中切换断点,它不会在里面停止。不会调用此方法。除了提交主表单之外,似乎什么都没有发生(即使我没有错误)。

在调试模式下单击确定按钮后,我可以在 PhaseListener beforePhase(PhaseEvent phaseEvent) 方法内停止。但是我真的不知道是否应该在PhaseListener beforePhase(PhaseEvent phaseEvent)方法之后调用backing bean方法。

我正在寻找有关如何调试它的任何提示?
单击对话框上的 Ok 按钮时是否调用了任何 javascript?


更新:问题似乎来自这样一个事实,即弹出窗口是从页面的一个区域调用并在另一个页面(包含该区域的主页)中定义的,如下面的代码所示:

main.xthml 内部:

<af:document>
  <af:form id="mainForm">
    <af:panelStretchLayout id="psl1" topHeight="auto" bottomHeight="0">
      <f:facet name="center">
        <af:region id="myRegion" showHeader="never"
                   value="#{main.regionModel}" />
      </f:facet>
    </af:panelStretchLayout>
  </af:form>
  <af:popup id="myPopup"
    binding="#{bkBean.myPopup}"
    contentDelivery="lazyUncached">
    <af:dialog id="myDialog" closeIconVisible="true"
      modal="true" okVisible="true" cancelVisible="true"
      title="Import from server to #{bkBean.file.name}"
      type="okCancel"
      dialogListener="#{bkBean.doSomething}">
      <af:panelFormLayout id="pfl1">
       <!-- Several input text here -->
      </af:panelFormLayout>
    </af:dialog>
  </af:popup>
</af:document>

在 myRegion.xhtml 中:

    <?xml version='1.0' encoding='UTF-8'?>
    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
              xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:trh="http://myfaces.apache.org/trinidad/html"
              xmlns:tr="http://myfaces.apache.org/trinidad"
              xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
      <af:tree ...>
      </af:tree>
      <!-- Contextual Menu -->
      <af:popup id="pp1" contentDelivery="lazyUncached">
        <af:menu>
          <af:commandMenuItem text="Do something" immediate="true"
 rendered="#{bkBean2.isRendered}" icon="icon.png" actionListener="#{bkBean2.showMyPopup}" />
        </af:menu>
      </af:popup>
    </ui:composition>

如果我在 myRegion.xhtml 中定义弹出窗口,它会起作用,但如果我在 main.xhtml 中定义弹出窗口,则不会。

感谢您提供有关如何使其与 main.xhtml 中定义的弹出窗口一起工作的任何提示?

【问题讨论】:

  • 点击取消时是否命中了你的方法?
  • 对话监听器不应该是dialogListener="#{ExportImportServerBean.importFromServer}"&gt; 可能是拼写错误。如果您按“ctrl”并单击jsff页面中的方法名称,您可以测试要调用的方法是否正确。导航是否将您带到方法?用你的 bean 写的?
  • 是的,如果我在我的 xhtml 页面中按住 ctrl 并单击它,它确实会将我带到我的 bean 中的方法。有没有办法调试呢?例如,我尝试输入dialogListener="#{bla bla}",它没有显示任何错误,什么也没有。这种行为正常吗?

标签: javascript jsf-2 oracle-adf


【解决方案1】:

你有两个选择:

  1. 尝试在 adfc-config.xml 中映射您的 bean,而不是使用注释。

  2. 保留注释并确保在 ADF 应用程序中使用启用 CDI,如下所示:

http://www.jobinesh.com/2014/08/enabling-cdi-in-adf-applications.html

值得一提的是,CDI(基于注释的 bean)并没有经常与 ADF 一起使用 - 至少关于遵循 CDI 方法的人的信息很少 - 所以你可能正走在未知的领域。

【讨论】:

  • 没有第三个选项 :) ?我没有使用 CDI,我使用 jboss-seam 2.3 进行注入。对不起,我没有在我的代码中说清楚。到目前为止,我的豆子都很好用。除了这个 dialogListener。但也许问题可能来自一些 servlet 过滤器或我的 web.xml 中的一些映射没有重定向到我的支持 bean 方法。完全相同的代码也适用于 Oracle ADF Faces 11。
  • 哇,这是我从未想过的鸡尾酒:Jboss Seam 和 ADF——我最喜欢的两个框架——放在同一个盘子里 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-21
  • 1970-01-01
  • 2018-08-08
  • 1970-01-01
  • 1970-01-01
  • 2016-10-27
  • 1970-01-01
相关资源
最近更新 更多