Search in sources :

Example 1 with TCKValidator

use of com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValidator in project faces by jakartaee.

the class TestServlet method setupTree.

private void setupTree(UIComponent root, UIData data) {
    FacesContext fc = getFacesContext();
    ELContext elContext = fc.getELContext();
    // Attach our UIData to the view root
    // UIData data = new UIData();
    data.setId("data");
    root.getChildren().add(data);
    // Set up columns with facets and fields for each property
    UIColumn column;
    UICommand command;
    UIInput input;
    UIOutput output;
    UIOutput label;
    UIOutput constant;
    column = new UIColumn();
    column.setId("commandColumn");
    label = new UIOutput();
    label.setId("commandHeader");
    label.setValue("Command Header");
    column.getFacets().put("header", label);
    label = new UIOutput();
    label.setId("commandFooter");
    label.setValue("Command Footer");
    column.getFacets().put("footer", label);
    command = new UICommand();
    command.setId("command");
    command.setValueExpression("value", getApplication().getExpressionFactory().createValueExpression(elContext, "#{foo.command}", Object.class));
    column.getChildren().add(command);
    data.getChildren().add(column);
    command.addActionListener(new TCKDataActionListener());
    column = new UIColumn();
    column.setId("inputColumn");
    label = new UIOutput();
    label.setId("inputHeader");
    label.setValue("Input Header");
    column.getFacets().put("header", label);
    label = new UIOutput();
    label.setId("inputFooter");
    label.setValue("Input Footer");
    column.getFacets().put("footer", label);
    input = new UIInput();
    input.setId("input");
    input.setValueExpression("value", getApplication().getExpressionFactory().createValueExpression(elContext, "#{foo.input}", Object.class));
    column.getChildren().add(input);
    data.getChildren().add(column);
    input.addValidator(new TCKValidator());
    input.addValueChangeListener(new TCKValueChangeListener());
    column = new UIColumn();
    column.setId("outputColumn");
    label = new UIOutput();
    label.setId("outputHeader");
    label.setValue("Output Header");
    column.getFacets().put("header", label);
    label = new UIOutput();
    label.setId("outputFooter");
    label.setValue("Output Footer");
    column.getFacets().put("footer", label);
    output = new UIOutput();
    output.setId("output");
    output.setValueExpression("value", getApplication().getExpressionFactory().createValueExpression(elContext, "#{foo.output}", Object.class));
    column.getChildren().add(output);
    data.getChildren().add(column);
    column = new UIColumn();
    column.setId("constantColumn");
    label = new UIOutput();
    label.setId("constantHeader");
    label.setValue("Constant Header");
    column.getFacets().put("header", label);
    label = new UIOutput();
    label.setId("constantFooter");
    label.setValue("Constant Footer");
    column.getFacets().put("footer", label);
    constant = new UIOutput();
    constant.setId("constant");
    constant.setValue("Constant Value");
    column.getChildren().add(constant);
    data.getChildren().add(column);
}
Also used : FacesContext(jakarta.faces.context.FacesContext) ELContext(jakarta.el.ELContext) TCKValidator(com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValidator) TCKValueChangeListener(com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValueChangeListener) UIColumn(jakarta.faces.component.UIColumn) UIOutput(jakarta.faces.component.UIOutput) UICommand(jakarta.faces.component.UICommand) UIInput(jakarta.faces.component.UIInput)

Example 2 with TCKValidator

use of com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValidator 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);
}
Also used : FacesContext(jakarta.faces.context.FacesContext) TCKValidator(com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValidator) ELContext(jakarta.el.ELContext) TCKValueChangeListener(com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValueChangeListener) MethodExpressionValidator(jakarta.faces.validator.MethodExpressionValidator) UIInput(jakarta.faces.component.UIInput) UIViewRoot(jakarta.faces.component.UIViewRoot) MethodExpression(jakarta.el.MethodExpression) PrintWriter(java.io.PrintWriter)

Example 3 with TCKValidator

use of com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValidator 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);
}
Also used : FacesContext(jakarta.faces.context.FacesContext) TCKValidator(com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValidator) ELContext(jakarta.el.ELContext) TCKValueChangeListener(com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValueChangeListener) MethodExpressionValidator(jakarta.faces.validator.MethodExpressionValidator) UIInput(jakarta.faces.component.UIInput) UIViewRoot(jakarta.faces.component.UIViewRoot) MethodExpression(jakarta.el.MethodExpression) PrintWriter(java.io.PrintWriter)

Example 4 with TCKValidator

use of com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValidator 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);
}
Also used : FacesContext(jakarta.faces.context.FacesContext) TCKValidator(com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValidator) TCKValueChangeListener(com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValueChangeListener) MethodExpressionValidator(jakarta.faces.validator.MethodExpressionValidator) UIInput(jakarta.faces.component.UIInput) UIViewRoot(jakarta.faces.component.UIViewRoot) MethodExpression(jakarta.el.MethodExpression) PrintWriter(java.io.PrintWriter)

Example 5 with TCKValidator

use of com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValidator in project faces by jakartaee.

the class TestServlet method uiInputValidate3cTest.

@Override
public void uiInputValidate3cTest(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();
    // If the new and previous values do not differ,
    // the listener will not be invoked.
    input.setSubmittedValue("value");
    input.setValue("value");
    TCKValueChangeListener.trace(null);
    TCKValidator.clearTrace();
    root.processValidators(context);
    String valTrace = TCKValidator.getTrace();
    if (!"/VL1/VL2".equals(valTrace)) {
        out.println("Test FAILED[3].  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("Test FAILED[3].  ValueChangeListener was incorrectly" + " invoked after a Validator marked the component as invalid.");
        return;
    }
    out.println(JSFTestUtil.PASS);
}
Also used : FacesContext(jakarta.faces.context.FacesContext) TCKValidator(com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValidator) TCKValueChangeListener(com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValueChangeListener) MethodExpressionValidator(jakarta.faces.validator.MethodExpressionValidator) UIInput(jakarta.faces.component.UIInput) UIViewRoot(jakarta.faces.component.UIViewRoot) MethodExpression(jakarta.el.MethodExpression) PrintWriter(java.io.PrintWriter)

Aggregations

TCKValidator (com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValidator)13 TCKValueChangeListener (com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValueChangeListener)13 UIInput (jakarta.faces.component.UIInput)13 FacesContext (jakarta.faces.context.FacesContext)13 MethodExpression (jakarta.el.MethodExpression)12 UIViewRoot (jakarta.faces.component.UIViewRoot)12 MethodExpressionValidator (jakarta.faces.validator.MethodExpressionValidator)12 PrintWriter (java.io.PrintWriter)12 ELContext (jakarta.el.ELContext)7 UISelectItem (jakarta.faces.component.UISelectItem)6 UIColumn (jakarta.faces.component.UIColumn)1 UICommand (jakarta.faces.component.UICommand)1 UIOutput (jakarta.faces.component.UIOutput)1