use of jakarta.faces.validator.MethodExpressionValidator in project faces by jakartaee.
the class TestServlet method methodExpressionValidatorCtor1Test.
public void methodExpressionValidatorCtor1Test(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter pw = response.getWriter();
try {
new MethodExpressionValidator();
pw.println(JSFTestUtil.PASS);
} catch (Exception e) {
pw.println("The no-arg constructor for MethodExpressionValidator " + "threw an unexpected exception");
e.printStackTrace();
}
}
use of jakarta.faces.validator.MethodExpressionValidator in project faces by jakartaee.
the class TestServlet method methodExpressionValidateNPETest.
public void methodExpressionValidateNPETest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter pw = response.getWriter();
FacesContext facesContext = getFacesContext();
if (facesContext == null) {
pw.println(JSFTestUtil.FAIL + " Unable to obtain FacesContext instance.");
return;
}
UIInput input = (UIInput) getApplication().createComponent(UIInput.COMPONENT_TYPE);
input.setId("input1");
input.setValue(new ServletException());
MethodExpressionValidator mev = new MethodExpressionValidator();
// Test for null FacesContext throws NPE
JSFTestUtil.checkForNPE(mev, "validate", new Class<?>[] { FacesContext.class, UIComponent.class, Object.class }, new Object[] { null, input, input.getValue() }, pw);
// Test for null UIComponent throws NPE
JSFTestUtil.checkForNPE(mev, "validate", new Class<?>[] { FacesContext.class, UIComponent.class, Object.class }, new Object[] { facesContext, null, input.getValue() }, pw);
}
use of jakarta.faces.validator.MethodExpressionValidator in project faces by jakartaee.
the class TestServlet method uiInputValidate3bTest.
public void uiInputValidate3bTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
UIInput input = (UIInput) createComponent();
FacesContext context = getFacesContext();
UIViewRoot root = getApplication().getViewHandler().createView(context, "/root.xhtml");
context.setViewRoot(root);
root.getChildren().add(input);
// Verify that a UIInput instance that has a local value,
// and the valid property is true all validators associated
// with the component are invoked, if the component is marked
// invalid by a validator, no listener is invoked.
input.setSubmittedValue("previous");
// Setup the validators
TCKValidator validator1 = new TCKValidator("VL1", false);
TCKValidator validator2 = new TCKValidator("VL2", true);
input.addValidator(validator1);
request.setAttribute("TCKValidator", validator2);
ELContext context2 = context.getELContext();
MethodExpression binding = getApplication().getExpressionFactory().createMethodExpression(context2, "#{requestScope.TCKValidator.validate}", null, new Class[] { FacesContext.class, UIComponent.class, Object.class });
MethodExpressionValidator validator = new MethodExpressionValidator(binding);
input.addValidator(validator);
// Setup the listeners
TCKValueChangeListener listener = new TCKValueChangeListener("VCL1");
input.addValueChangeListener(listener);
input.setSubmittedValue("new-value");
TCKValueChangeListener.trace(null);
TCKValidator.clearTrace();
root.processValidators(context);
// All validators succeed, and the value differs from the previous.
// ensure the listener was invoked.
validator2.markInvalid(false);
TCKValueChangeListener.trace(null);
TCKValidator.clearTrace();
input.setValid(true);
root.processValidators(context);
String valTrace = TCKValidator.getTrace();
if (!"/VL1/VL2".equals(valTrace)) {
out.println(JSFTestUtil.FAIL + " Validator trace did not return as " + "expected.");
out.println("Traced expected: /VL1/VL2");
out.println("Trace received: " + valTrace);
return;
}
String listenerTrace = TCKValueChangeListener.trace();
if (!"/VCL1@ANY_PHASE".equals(listenerTrace)) {
out.println(JSFTestUtil.FAIL + " Unexpected listener trace.");
out.println("Expected: /VCL1@ANY_PHASE");
out.println("Received: " + listenerTrace);
return;
}
out.println(JSFTestUtil.PASS);
}
use of jakarta.faces.validator.MethodExpressionValidator in project faces by jakartaee.
the class TestServlet method uiInputValidate3aTest.
public void uiInputValidate3aTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
UIInput input = (UIInput) createComponent();
FacesContext context = getFacesContext();
UIViewRoot root = getApplication().getViewHandler().createView(context, "/root.xhtml");
context.setViewRoot(root);
root.getChildren().add(input);
// Verify that a UIInput instance that has a local value,
// and the valid property is true all validators associated
// with the component are invoked, if the component is marked
// invalid by a validator, no listener is invoked.
input.setSubmittedValue("previous");
// Setup the validators
TCKValidator validator1 = new TCKValidator("VL1", false);
TCKValidator validator2 = new TCKValidator("VL2", true);
input.addValidator(validator1);
request.setAttribute("TCKValidator", validator2);
ELContext context2 = context.getELContext();
MethodExpression binding = getApplication().getExpressionFactory().createMethodExpression(context2, "#{requestScope.TCKValidator.validate}", null, new Class[] { FacesContext.class, UIComponent.class, Object.class });
MethodExpressionValidator validator = new MethodExpressionValidator(binding);
input.addValidator(validator);
// Setup the listeners
TCKValueChangeListener listener = new TCKValueChangeListener("VCL1");
input.addValueChangeListener(listener);
input.setSubmittedValue("new-value");
TCKValueChangeListener.trace(null);
TCKValidator.clearTrace();
root.processValidators(context);
String valTrace = TCKValidator.getTrace();
if (!"/VL1/VL2".equals(valTrace)) {
out.println(JSFTestUtil.FAIL + " Validator trace did not return as " + "expected.");
out.println("Traced expected: /VL1/VL2");
out.println("Trace received: " + valTrace);
return;
}
String listenerTrace = TCKValueChangeListener.trace();
if (listenerTrace.length() != 0) {
out.println(JSFTestUtil.FAIL + " ValueChangeListener was incorrectly" + " invoked after a Validator marked the component as invalid.");
return;
}
out.println(JSFTestUtil.PASS);
}
use of jakarta.faces.validator.MethodExpressionValidator in project faces by jakartaee.
the class TestServlet method uiInputValidate3aTest.
@Override
public void uiInputValidate3aTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
UIInput input = (UIInput) createComponent();
FacesContext context = getFacesContext();
UIViewRoot root = getApplication().getViewHandler().createView(context, "/root.xhtml");
context.setViewRoot(root);
root.getChildren().add(input);
// Verify that a UIInput instance that has a local value,
// and the valid property is true all validators associated
// with the component are invoked, if the component is marked
// invalid by a validator, no listener is invoked.
input.setSubmittedValue("previous");
input.setRendererType(null);
// Setup the validators
TCKValidator validator1 = new TCKValidator("VL1", false);
TCKValidator validator2 = new TCKValidator("VL2", true);
input.addValidator(validator1);
request.setAttribute("TCKValidator", validator2);
MethodExpression binding = getApplication().getExpressionFactory().createMethodExpression(context.getELContext(), "#{requestScope.TCKValidator.validate}", null, new Class[] { FacesContext.class, UIComponent.class, Object.class });
MethodExpressionValidator validator = new MethodExpressionValidator(binding);
input.addValidator(validator);
// Setup the listeners
TCKValueChangeListener listener = new TCKValueChangeListener("VCL1");
input.addValueChangeListener(listener);
input.setSubmittedValue("new-value");
TCKValueChangeListener.trace(null);
TCKValidator.clearTrace();
root.processValidators(context);
String valTrace = TCKValidator.getTrace();
if (!"/VL1/VL2".equals(valTrace)) {
out.println(JSFTestUtil.FAIL + " Validator trace did not return as " + "expected.");
out.println("Traced expected: /VL1/VL2");
out.println("Trace received: " + valTrace);
return;
}
String listenerTrace = TCKValueChangeListener.trace();
if (listenerTrace.length() != 0) {
out.println(JSFTestUtil.FAIL + " ValueChangeListener was incorrectly" + " invoked after a Validator marked the component as invalid.");
return;
}
out.println(JSFTestUtil.PASS);
}
Aggregations