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 ;-)
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 ;-)
Share Improve this question edited Feb 20, 2014 at 21:17 John Dalsgaard asked Feb 20, 2014 at 15:56 John DalsgaardJohn Dalsgaard 2,8071 gold badge15 silver badges26 bronze badges 1- hmm - same here: none of your 2 options will be working or me. While {params: {"valmode": 0}} can't be correct in the first place, if I'm getting Sven right it should be just {valmode: 0} without the params part (or maybe {valmode: '0'}..?) – Lothar Mueller Commented Feb 21, 2014 at 0:01
3 Answers
Reset to default 13Here 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 .ibm.xsp.context.ExternalContextEx;
import .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}} );
The parameter valmode sets the validation mode and has the following options:
0 for no validation
1 for execution of converters only
2 for execution of converters & validators
For older versions (<8.5.2) it is just true or false.
EDIT: This works for ClientSide Validation only.
Never tried that before, but according to my copy of the Xpages Portable Command Guide we can send variuous kinds of POST request parameters (I grew to like that book a lot recently...). So I gave it a quick shot and it seems to work on my side. Here's the setup:
- Xpage with 2 buttons plus a panel (id = "fieldContainer").
- Inside the panel sits a simple inputText control with an active required validator.
- A button
The button calls the following CSJS script:
var opt={disableVal":"true"}; //pass param value as text
XSP.partialRefreshPost("#{id:fieldContainer}", {params: opt});
To my inputText I add the following SSJS code under "All Properties > data > disableValidators":
if(!params.isEmpty()){
if(param.get("disableVal")==="true"){true}
}
To verify that the refresh indeed took place I added a putedField control into the same panel bound to a SSJS code showing me the current data/time value:
@Now()
Hope this helps
EDIT:
the book also mentions an option to pass an immediate parameter, but that most probably would not only suppress validation but also submission and conversion of submitted values (I didn't try that one, but nevertheless here's the syntax as described therein):
XSP.partialRefreshPost("#{id:idOfControl}", {immediate: true});