在AEM中如何在组件对话框中添加一个名为“listeners”的新节点,而不使用dialog.xml文件

时间:2017-08-29 06:40:25

标签: aem

我正在使用“提交前”监听器对我的选择框进行一些验证 我已经提到以下链接: https://helpx.adobe.com/experience-manager/using/classic_dialog_validation.html

但是“提交前”方法仅在我放置时调用, 对话框根级别中的对话框侦听器。

如何在对话框根级别放置对话框监听器(我在项目中检查过没有dialog.xml文件,他们只使用java代码构建组件对话框)。

任何人都可以帮助我吗?enter image description here

Dialog属性构造代码:

@DialogField(name =“./ validateProgram”,

fieldLabel =“验证程序”,

fieldDescription = "(synchronized)",

        additionalProperties = {
                 @Property(renderIn = Property.RenderValue.TOUCH,
                                name = "validation",
                                value = "validation-program")
                 },

         listeners = {
             @Listener(name ="beforesubmit",
                          value = "function(dialog){" + 
                        "return programValidation.beforeSubmit(dialog);"+ 
                       "}")
                    })

       @Selection(
                type ="select",
                optionsProvider = " ",
                dataSource = "/resourcetype/data")

       public final String validateProgram;

Java脚本代码:

window.onload = function(){

 programValidation.init();

};

var programValidation = programValidation || (函数($){

function initialize() {
};

function validate() {
    alert("inside validate method");
    var res = true;
    return res;
};

return {
    beforeSubmit: validate,        
    init: initialize
}

})(jQuery的);

2 个答案:

答案 0 :(得分:0)

您正在使用cq component maven plugin这是一条非常重要的信息,可以回答您的问题。

之前我没有使用过此插件,但在您的情况下,我假设您正在寻找Listener注释,您可以将其设置为beforesubmit,将值设置为function(){alert(1)}

您可能需要在局部变量上设置注释,类似于注释对话框字段“@DialogField”的方式,在此处的插件的使用页面中查找更多文档:{{3 }}

希望这有帮助。

答案 1 :(得分:0)

感谢您的支持。找到了以下解决问题的方法。

我在2个侦听器中添加了ValidateFields方法(FIELD_LISTENER_LOAD_CONTENT和FIELD_LISTENER_SELECTION_CHANGED)

function ValidateFields(dialog) {
dialog.on("beforesubmit", function(e) {
   if(<condtion failed>)
    CQ.Ext.Msg.alert(CQ.I18n.getMessage("Error"), CQ.I18n.getMessage("<error message>"));
    return false;
   } else {
    return true;
   }
}, this);
}