Search in sources :

Example 1 with TCKConverter

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

the class TestServlet method uiInputValidate4Test.

@Override
public void uiInputValidate4Test(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    UIInput input = (UIInput) createComponent();
    input.setRendererType(null);
    UISelectItem item1 = new UISelectItem();
    item1.setItemValue("converted");
    UISelectItem item2 = new UISelectItem();
    item2.setItemValue("converted2");
    input.getChildren().add(item1);
    input.getChildren().add(item2);
    FacesContext context = getFacesContext();
    UIViewRoot root = getApplication().getViewHandler().createView(context, "/root.xhtml");
    context.setViewRoot(root);
    root.getChildren().add(input);
    Converter converter = new TCKConverter();
    input.setConverter(converter);
    input.setSubmittedValue("new");
    input.setValid(true);
    input.setRequired(true);
    input.validate(context);
    if (!"converted".equals(input.getValue())) {
        out.println(JSFTestUtil.FAIL + " Converter available to the component" + " via getConverter(), but the converter wasn't called.");
        out.println("Expected the value after conversion to be 'converted'");
        out.println("Value received: " + input.getValue());
        return;
    }
    // now verify the proper behavior if conversion fails
    input.setSubmittedValue("fail");
    input.validate(context);
    if (input.isValid()) {
        out.println(JSFTestUtil.FAIL + " Conversion failure should have resulted" + " in the component in question being marked as invalid.");
        return;
    }
    if (JSFTestUtil.getAsArray(context.getMessages()).length < 1) {
        out.println(JSFTestUtil.FAIL + " No messages queued as required in the " + "case of conversion failure.");
        return;
    }
    out.println(JSFTestUtil.PASS);
}
Also used : FacesContext(jakarta.faces.context.FacesContext) TCKConverter(com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKConverter) TCKConverter(com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKConverter) Converter(jakarta.faces.convert.Converter) UIInput(jakarta.faces.component.UIInput) UIViewRoot(jakarta.faces.component.UIViewRoot) PrintWriter(java.io.PrintWriter) UISelectItem(jakarta.faces.component.UISelectItem)

Example 2 with TCKConverter

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

the class TestServlet method uiInputValidate4Test.

public void uiInputValidate4Test(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    UIInput input = (UIInput) createComponent();
    input.setRendererType(null);
    FacesContext context = getFacesContext();
    UIViewRoot root = getApplication().getViewHandler().createView(context, "/root.xhtml");
    context.setViewRoot(root);
    root.getChildren().add(input);
    Converter converter = new TCKConverter();
    input.setConverter(converter);
    input.setSubmittedValue("value");
    input.setValid(true);
    input.setRequired(true);
    input.validate(context);
    if (!"converted".equals(input.getValue())) {
        out.println(JSFTestUtil.FAIL + " Converter available to the component" + " via getConverter(), but the converter wasn't called.");
        out.println("Expected the value after conversion to be 'converted'");
        out.println("Value received: " + input.getValue());
        return;
    }
    // now verify the proper behavior if conversion fails
    input.setSubmittedValue("fail");
    input.validate(context);
    if (input.isValid()) {
        out.println(JSFTestUtil.FAIL + " Conversion failure should have resulted" + " in the component in question being marked as invalid.");
        return;
    }
    if (JSFTestUtil.getAsArray(context.getMessages()).length != 1) {
        out.println(JSFTestUtil.FAIL + " No messages queued as required in the " + "case of conversion failure.");
        return;
    }
    out.println(JSFTestUtil.PASS);
}
Also used : FacesContext(jakarta.faces.context.FacesContext) TCKConverter(com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKConverter) TCKConverter(com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKConverter) Converter(jakarta.faces.convert.Converter) UIInput(jakarta.faces.component.UIInput) UIViewRoot(jakarta.faces.component.UIViewRoot) PrintWriter(java.io.PrintWriter)

Aggregations

TCKConverter (com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKConverter)2 UIInput (jakarta.faces.component.UIInput)2 UIViewRoot (jakarta.faces.component.UIViewRoot)2 FacesContext (jakarta.faces.context.FacesContext)2 Converter (jakarta.faces.convert.Converter)2 PrintWriter (java.io.PrintWriter)2 UISelectItem (jakarta.faces.component.UISelectItem)1