Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

javascript - How to disable validators using the XSP.partialRefreshPost method?

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).

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???

Anyone knows how to do this?

EDIT:

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.

First, using the "immediate" paramter:

$(".selectCtrl").on("change", function(e){XSP.partialRefreshPost("#{id:repeatCtrl}", {immediate: true})})

Then, using the "valmode" paramter:

$(".selectCtrl").on("change", function(e){XSP.partialRefreshPost("#{id:repeatCtrl}", {params: {'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 ;-)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;
    }

}

You just have to add a parameter to your PartialRefresh, and the validation is disabled:

XSP.partialRefreshPost('#{id:refreshMe}', {'params': {'disableValidation':true}} );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...