如何使用XSP.partialRefreshPost方法禁用验证器? [英] How to disable validators using the XSP.partialRefreshPost method?
问题描述
我正在使用XSP.partialRefreshPost来触发客户端Javascript的部分刷新。我希望能够在不触发验证器的情况下进行局部刷新(这只是普通输入控件的一个简单属性)。
I am using XSP.partialRefreshPost to trigger a partial refresh from client side Javascript. I would like to be able to do the partial refresh without triggering the validators (which is just a simple attribute on an ordinary input control).
我找到了几个引用一个选项参数,可以与XSP.partialRefreshPost结合使用(包括控制验证的能力)。但是,我没有找到任何描述语法/选项名称的地方???
I have found several references to an "options" argument that you can use in conjuntion with XSP.partialRefreshPost (including the ability to control validation). However, I have not found any places that describes the syntax/option names???
任何人都知道怎么做?
编辑:
好的,我添加了几个我尝试过的例子 - 澄清问题。我也在XPages便携式命令指南中嗤之以鼻。
Ok, I have added a couple of examples of what I have tried - to clarify the issue. I have had my nose in the XPages Portable Command Guide as well.
首先,使用立即参数:
$(".selectCtrl").on("change", function(e){XSP.partialRefreshPost("#{id:repeatCtrl}", {immediate: true})})
然后,使用valmode参数:
Then, using the "valmode" paramter:
$(".selectCtrl").on("change", function(e){XSP.partialRefreshPost("#{id:repeatCtrl}", {params: {'valmode': 0}})})
后者在valmode附近引用了各种报价, 0。
The latter with variations of quotes around "valmode" and "0".
这些都不起作用......(即刷新开始 - 但由验证器失败而停止)。我希望我在这里得到错误的语法 - 但是找不到任何有用的例子 - 但是; - )
None of these worked... (i.e. the refresh kicks in - but is stopped by the validator failing). I hope that I am just getting the wrong syntax here - but haven't been able to find any working examples - yet ;-)
推荐答案
这是 PhaseListener ,如果需要,它会禁用验证:
Here is a PhaseListener which disables the validation if required:
package ch.hasselba.demo;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import com.ibm.xsp.context.ExternalContextEx;
import com.ibm.xsp.context.FacesContextExImpl;
public class DisableValidationPhaseListener implements PhaseListener {
private static final long serialVersionUID = 1L;
public void afterPhase(PhaseEvent arg0) {}
public void beforePhase(PhaseEvent arg0) {
FacesContextExImpl fc = (FacesContextExImpl) arg0.getFacesContext();
ExternalContextEx ec = (ExternalContextEx) fc.getExternalContext();
// check for the "disableValidation" parameter & disable validation
// if required
if( ec.getRequestParameterMap().containsKey("disableValidation") )
fc.setDisableValidators(true);
}
public PhaseId getPhaseId() {
return PhaseId.PROCESS_VALIDATIONS;
}
}
您只需要添加一个参数到你的PartialRefresh,并且验证被禁用:
You just have to add a parameter to your PartialRefresh, and the validation is disabled:
XSP.partialRefreshPost('#{id:refreshMe}', {'params': {'disableValidation':true}} );
这篇关于如何使用XSP.partialRefreshPost方法禁用验证器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!