【问题标题】:How to validate before open a Popup in ADF?如何在 ADF 中打开弹出窗口之前进行验证?
【发布时间】:2018-11-25 04:09:27
【问题描述】:

我在 adf 中有一个 jspx 页面,其中包含一个“命令链接”,单击命令链接时,会通过“showPopupBehaviour”的定义属性打开一个弹出窗口。

但我想在单击 CommandLink 时验证某些内容,如果验证返回 True,则只有弹出窗口应该打开,否则如果在验证期间返回 False,则会出现相关消息。我对此进行了探索,并尝试使用以下代码以编程方式调用 Popup,但没有成功,甚至在单击 CommandLink 时也没有打开任何弹出窗口。

下面是我尝试过的代码:

/* Below method "showPopup_aug" is invoked through actionListener of CommandLink */

public void showPopup_aug(ActionEvent evt_popup) {
    System.out.println("entered in showPopup_aug method");

    RichPopup popup_aug = (RichPopup)JSFUtils.findComponentInRoot("pop_aug");

    System.out.println("Popup_id="+popup_aug.getId());

    /*
    //pop_aug.PopupHints hints_aug = new RichPopup.PopupHints();

    RichPopup.PopupHints hints_aug = new RichPopup.PopupHints();
    popup_aug.show(hints_aug);       

    System.out.println("Popup-Aug opened");        

    */
    System.out.println("before calling showPopup method");

    showPopup(popup_aug, true);

    System.out.println("Popup-Aug opened"); 

}

下面的方法“showPopup”被调用以根据从“showPopup_aug”方法接收的参数打开一个弹出窗口:

public static void showPopup(RichPopup pop, boolean visible) {
    try {
        System.out.println("entered in showPopup code");
        FacesContext context = FacesContext.getCurrentInstance();
        if (context != null && pop != null) {
            //String popupId = pop.getClientId(context);
            String popupId = pop.getId();

            System.out.println("ClientID of popup="+popupId);

            if (popupId != null) {
                System.out.println("Client PopupID is not null");

                StringBuilder script = new StringBuilder();
                script.append("var popup = AdfPage.PAGE.findComponent('").append(popupId).append("'); ");
                if (visible) {
                    script.append("if (!popup.isPopupVisible()) { ").append("popup.show();}");
                } else {
                    script.append("if (popup.isPopupVisible()) { ").append("popup.hide();}");
                }
                ExtendedRenderKitService erks = Service.getService(context.getRenderKit(), ExtendedRenderKitService.class);
                erks.addScript(context, script.toString());
            }
        }
        System.out.println("completion of showPopup code");
    }
    catch (Exception e) {
        System.out.println("exception occured in showPopup code="+e.getMessage());
        throw new RuntimeException(e);
    }
}

我想在 ADF 应用程序中打开 adf Popup 之前执行验证或操作。

【问题讨论】:

标签: oracle jsf oracle-adf


【解决方案1】:

所以你在这里的目标是打开弹出程序的方式。为什么使用 JSFUtils 得到弹出窗口?您可以将 af:popup 绑定到您的支持 bean 并使用它。您不需要使用 javascript。

private RichPopup myPopup ;//bound to the UI component

 public void showOrHidePopup(RichPopup popup,Boolean visible){
 if(visible){
 RichPopup.PopupHints hints = new RichPopup.PopupHints();
   myPopup.show(hints);
 }
 else{
  myPopup.hide();
 }

https://coderoar.blogspot.com/2018/08/oracle-adf-show-or-hide-popup.html

所以在 commandLink actionListener 中执行验证并在其中调用此方法。

谢谢,

普里亚

【讨论】:

    【解决方案2】:

    我从您的问题中了解到,您需要在命令链接点击时进行验证。如果验证返回真,那么它应该打开弹出窗口......否则应该显示一些错误消息。 有了这个理解,我的做法是..

    如果在 action_listner 上,您正在调用 showPopup_aug,那么在 showPopup_aug 中,调用验证函数,该函数返回 true 或 false(布尔数据类型)...

    类似的东西。

        public boolean validateFields() {
          if()
            return true;
          else
            return false;
          }
    

    在 showPopup_aug 中,

           public void showPopup_aug(ActionEvent evt_popup) {
           if(validateFields())
           {
             showPopup(popup_aug);//defination given below
           }
           else
           {
                    FacesMessage fm = new FacesMessage("Error Message");
                    fm.setSeverity(FacesMessage.SEVERITY_ERROR);
                    FacesContext fctx = FacesContext.getCurrentInstance();
                    fctx.addMessage(null, fm);            
           }
         }
    
         public void showPopup(RichPopup popup) {
            RichPopup.PopupHints hint = new RichPopup.PopupHints();
            popup.show(hint);
         }
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多