对于ADF按钮类组件,如:<af:commandButton>,<af:commandLink>,点击时,无论是否设置局部提交,都会往后台发送请求,但有时我们希望前台js先进行判断,然后再决定是否往后台发送请求。在这种情况下,设置其disabled="false"是实现不了的。
解决方法:
可通过对ADF按钮类组件的AdfActionEvent事件的propagatesToServer()进行重写返回false即可
如下就是根据输入框的值是否为空串,如果是空串则不往后台发请求:
<af:resource type="javascript">
function preventToServer(evt){
var ui = AdfPage.PAGE.findComponentByAbsoluteId("it1");
var value = ui.getProperty("value");
if(""==value){
evt.propagatesToServer = function(){
return false;
}
}
evt.cancel();
}
</af:resource>
<af:messages id="m1"/>
<af:form id="f1">
<af:inputText label="Label 1" id="it1"/>
<af:commandButton text="commandButton 1" id="cb1">
<af:clientListener type="action" method="preventToServer"/>
</af:commandButton>