在具有错误值的关闭对话框中未调用ADF弹出取消侦听器

时间:2018-01-05 21:07:11

标签: jsf richfaces oracle-adf

问题是当我在对话框组件中的inputBox中输入一些负值时,验证器会抛出类似“不允许负数”的错误。对话框现在有一个标有红色边框的错误输入框,我决定在对话框外面单击以关闭它并重置输入框,但是inputBox没有重置,如果按Esc键或Ok按钮,则只调用popupCanceledListener并重置inputBox。下面是代码,其中包含一个带有对话框和inputBox的弹出窗口。

JSF代码:

<af:popup contentDelivery="lazyUncached" autoCancel="enabled"
          popupCanceledListener="#{pageFlowScope.testBean.handleResetPopup}"
          childCreation="deferred" id="testPopup">
   <af:dialog type="none" modal="false"
     id="Dlg1">
     <af:inputText label="DECIMAL PLACES"
                    columns="2"
                    validator="#{pageFlowScope.testBean.validateDecimalPlaceValue}"
                    value="#{pageFlowScope.testBean.decimalPlace}"
                    id="input1" autoSubmit="true"></af:inputText>
    <f:facet name="acceptNFChange">
      <af:commandButton text="OK" id="cb1"
                        actionListener="#{pageFlowScope.testBean.handleOkFromPopup}"
                        partialSubmit="true"></af:commandButton>
    </f:facet>
  </af:dialog>
</af:popup>

Bean代码:

    public void handleResetPopup(PopupCanceledEvent popupCanceledEvent) {
    try {
        UIComponent component = popupCanceledEvent.getComponent();
        RichInputText inputText = (RichInputText)JSFUtil.findComponent(component, "input1");
        inputText.resetValue();
    } catch (Throwable th) {
        this.handleException(th);
    }
}

问题:在对话框外部单击以关闭它并重置输入框时,不会调用popupCanceledListener。

2 个答案:

答案 0 :(得分:1)

最好的方法是使用类型为popupClosed的客户端侦听器。以下是您的代码示例:

<af:popup contentDelivery="lazyUncached" autoCancel="enabled"
          popupCanceledListener="#{pageFlowScope.testBean.handleResetPopup}"
          childCreation="deferred" id="testPopup">
   <af:dialog type="none" modal="false"
     id="Dlg1">
     <af:inputText label="DECIMAL PLACES"
                    columns="2"
                    validator="#{pageFlowScope.testBean.validateDecimalPlaceValue}"
                    value="#{pageFlowScope.testBean.decimalPlace}"
                    id="input1" autoSubmit="true"></af:inputText>
    <f:facet name="acceptNFChange">
      <af:commandButton text="OK" id="cb1"
                        actionListener="#{pageFlowScope.testBean.handleOkFromPopup}"
                        partialSubmit="true"></af:commandButton>
    </f:facet>
  </af:dialog>
  <af:clientListener type="popupClosed" method="popupCloseClientListener"/> 
  <af:serverListener type="popupClosedEvent" method="#{pageFlowScope.testBean.handlePopupClosed}"/>
</af:popup>

然后你需要在JSF脚本中写一些地方:

<script>
    function popupCloseClientListener(event) {
       component = event.getSource();
       AdfCustomEvent.queue(component,
                            "popupClosedEvent",
                            {payload:component.getSubmittedValue()},
                            true);
       event.cancel();
 }
 </script> ]]>

通过这种方式,您始终可以正确处理来自客户端的弹出窗口关闭事件。并实现您需要的所有服务器逻辑。

答案 1 :(得分:0)

此链接 https://community.oracle.com/thread/4112016 中提供的解决方案适用于我的方案。