Search in sources :

Example 16 with UIForm

use of jakarta.faces.component.UIForm in project faces by jakartaee.

the class Issue2578Bean method getContainingForm.

private UIComponent getContainingForm(UIComponent component) {
    UIComponent previous = component;
    UIComponent parent = component.getParent();
    while (parent != null) {
        if (parent instanceof UIForm) {
            return parent;
        }
        previous = parent;
        parent = parent.getParent();
    }
    return previous;
}
Also used : UIComponent(jakarta.faces.component.UIComponent) UIForm(jakarta.faces.component.UIForm)

Example 17 with UIForm

use of jakarta.faces.component.UIForm in project faces by jakartaee.

the class TestServlet method uiDataPositiveInvokeOnComponentTest.

public void uiDataPositiveInvokeOnComponentTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    final PrintWriter out = response.getWriter();
    out.println("beginning uiDataPositiveInvokeOnComponentTest");
    initDataModel();
    // Create UIData component
    UIData data = (UIData) createComponent();
    data.setFirst(3);
    data.setRows(5);
    data.setVar("foo");
    data.setValue(testDM);
    if (data.getValue() == null || testDM != data.getValue()) {
        out.println(JSFTestUtil.FAIL + JSFTestUtil.NL + " Bad value for data.getValue()");
        return;
    }
    // build component tree
    UIViewRoot viewRoot = new UIViewRoot();
    viewRoot.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
    viewRoot.setViewId("/view.xhtml");
    getFacesContext().setViewRoot(viewRoot);
    UIForm form1 = new UIForm();
    form1.setId("form1");
    viewRoot.getChildren().add(form1);
    setupTree(form1, data);
    // find the data component
    UIData data1 = (UIData) viewRoot.findComponent("form1:data");
    boolean found = false;
    data1.setRowIndex(3);
    if (!checkRowIndex(data1, 3, out)) {
        return;
    }
    found = viewRoot.invokeOnComponent(getFacesContext(), "form1:data:4:commandHeader", new ContextCallback() {

        public void invokeContextCallback(FacesContext context, UIComponent component) {
            out.println("entering invokeContextCallback()");
            UIData data = (UIData) getNamingContainer(component);
            UIForm form = (UIForm) getNamingContainer(data);
            if (!checkRowIndex(data, 4, out)) {
                return;
            }
            if (!"form1".equals(form.getId())) {
                out.println(JSFTestUtil.FAIL + JSFTestUtil.NL + "Incorrect form id" + JSFTestUtil.NL + "Expected: form1" + JSFTestUtil.NL + "Computed: " + form.getId());
            }
            if (!"commandHeader".equals(component.getId())) {
                out.println(JSFTestUtil.FAIL + JSFTestUtil.NL + "Incorrect component id" + JSFTestUtil.NL + "Expected: commandHeader" + JSFTestUtil.NL + "Computed: " + component.getId());
            }
        }
    });
    if (!checkRowIndex(data1, 3, out)) {
        return;
    }
    if (!found) {
        out.println(JSFTestUtil.FAIL + JSFTestUtil.NL + "Call to invokeOnComponent() returned false");
        return;
    }
    out.println(JSFTestUtil.PASS);
}
Also used : FacesContext(jakarta.faces.context.FacesContext) ContextCallback(jakarta.faces.component.ContextCallback) UIComponent(jakarta.faces.component.UIComponent) UIForm(jakarta.faces.component.UIForm) UIViewRoot(jakarta.faces.component.UIViewRoot) PrintWriter(java.io.PrintWriter) UIData(jakarta.faces.component.UIData)

Example 18 with UIForm

use of jakarta.faces.component.UIForm in project faces by jakartaee.

the class TestServlet method uiDataFEInvokeOnComponentTest.

public void uiDataFEInvokeOnComponentTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.println("beginning uiDataFEInvokeOnComponentTest");
    initDataModel();
    // Create UIData component
    UIData data = (UIData) createComponent();
    data.setFirst(3);
    data.setRows(5);
    data.setVar("foo");
    data.setValue(testDM);
    if (data.getValue() == null || testDM != data.getValue()) {
        out.println(JSFTestUtil.FAIL + JSFTestUtil.NL + " Bad value for data.getValue()");
        return;
    }
    // build component tree
    UIViewRoot viewRoot = new UIViewRoot();
    viewRoot.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
    viewRoot.setViewId("/view.xhtml");
    getFacesContext().setViewRoot(viewRoot);
    UIForm form1 = new UIForm();
    form1.setId("form1");
    viewRoot.getChildren().add(form1);
    setupTree(form1, data);
    // foundComponent = null;
    FacesContext context = getFacesContext();
    boolean result = false;
    // Negative case 1, not found component.
    result = viewRoot.invokeOnComponent(context, "form1:input7", new ContextCallback() {

        public void invokeContextCallback(FacesContext context, UIComponent component) {
            foundComponent = component;
        }
    });
    if (result) {
        out.println(JSFTestUtil.FAIL + " Expected \"false\" returned by" + " InvokeOnComponent() when passing in \"form:input7\"" + " as clientId arg. Instead received " + result);
        return;
    }
    // Negative case 2A, callback throws exception with found component
    try {
        result = viewRoot.invokeOnComponent(context, "form1:data:4:commandHeader", new ContextCallback() {

            public void invokeContextCallback(FacesContext context, UIComponent component) {
                foundComponent = component;
                // this exception?
                throw new IllegalStateException();
            }
        });
    } catch (Exception e) {
        if (!(e instanceof FacesException)) {
            out.println(JSFTestUtil.FAIL + "invokeOnComponent(facesContext," + " form2:input2, Callback) threw an Exception," + " but it wasn't an instance of FacesException.");
            out.println("Exception received: " + e.getClass().getName());
            return;
        }
    }
    // Negative case 2B, callback throws exception with not found component
    try {
        result = viewRoot.invokeOnComponent(context, "form2:input6", new ContextCallback() {

            public void invokeContextCallback(FacesContext context, UIComponent component) {
                foundComponent = component;
                // this exception?
                throw new IllegalStateException();
            }
        });
    } catch (Exception e) {
        if (!(e instanceof FacesException)) {
            out.println(JSFTestUtil.FAIL + "invokeOnComponent(facesContext," + " form2:input6, Callback) threw an Exception," + " but it wasn't an instance of FacesException.");
            out.println("Exception received: " + e.getClass().getName());
            return;
        }
    }
    out.println(JSFTestUtil.PASS);
}
Also used : FacesContext(jakarta.faces.context.FacesContext) ContextCallback(jakarta.faces.component.ContextCallback) UIComponent(jakarta.faces.component.UIComponent) UIForm(jakarta.faces.component.UIForm) UIViewRoot(jakarta.faces.component.UIViewRoot) ServletException(jakarta.servlet.ServletException) FacesException(jakarta.faces.FacesException) IOException(java.io.IOException) FacesException(jakarta.faces.FacesException) PrintWriter(java.io.PrintWriter) UIData(jakarta.faces.component.UIData)

Example 19 with UIForm

use of jakarta.faces.component.UIForm in project faces by jakartaee.

the class TestServlet method uiDataNPEInvokeOnComponentTest.

// End uiDataProcessDecodesNPETest
public void uiDataNPEInvokeOnComponentTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.println("beginning uiDataNPEInvokeOnComponentTest");
    initDataModel();
    // Create UIData component
    UIData data = (UIData) createComponent();
    data.setFirst(3);
    data.setRows(5);
    data.setVar("foo");
    data.setValue(testDM);
    if (data.getValue() == null || testDM != data.getValue()) {
        out.println(JSFTestUtil.FAIL + JSFTestUtil.NL + " Bad value for data.getValue()");
        return;
    }
    // build component tree
    UIViewRoot viewRoot = new UIViewRoot();
    viewRoot.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
    viewRoot.setViewId("/view.xhtml");
    getFacesContext().setViewRoot(viewRoot);
    UIForm form1 = new UIForm();
    form1.setId("form1");
    viewRoot.getChildren().add(form1);
    setupTree(form1, data);
    int npesCaught = 0;
    try {
        viewRoot.invokeOnComponent(null, "form1:data:4:commandHeader", new ContextCallback() {

            public void invokeContextCallback(FacesContext context, UIComponent component) {
            }
        });
        out.println(JSFTestUtil.FAIL + "invokeOnComponent() called with");
        out.println("null FacesContext argument did not throw an exception");
    } catch (Exception e) {
        if (!(e instanceof NullPointerException)) {
            out.println(JSFTestUtil.FAIL + "invokeOnComponent() called with");
            out.println("null FacesContext argument did not throw a");
            out.println("NullPointerException, instead threw " + e.getClass().getName());
        } else {
            ++npesCaught;
        }
    }
    try {
        viewRoot.invokeOnComponent(getFacesContext(), null, new ContextCallback() {

            public void invokeContextCallback(FacesContext context, UIComponent component) {
            }
        });
        out.println(JSFTestUtil.FAIL + "invokeOnComponent() called with");
        out.println("null clientId argument did not throw an exception");
    } catch (Exception e) {
        if (!(e instanceof NullPointerException)) {
            out.println(JSFTestUtil.FAIL + "invokeOnComponent() called with");
            out.println("null clientId argument did not throw a");
            out.println("NullPointerException, instead threw " + e.getClass().getName());
        } else {
            ++npesCaught;
        }
    }
    try {
        viewRoot.invokeOnComponent(getFacesContext(), "form1:data:4:commandHeader", null);
        out.println(JSFTestUtil.FAIL + "invokeOnComponent() called with");
        out.println("null callback argument did not throw an exception");
    } catch (Exception e) {
        if (!(e instanceof NullPointerException)) {
            out.println(JSFTestUtil.FAIL + "invokeOnComponent() called with");
            out.println("null callback argument did not throw a");
            out.println("NullPointerException, instead threw " + e.getClass().getName());
        } else {
            ++npesCaught;
        }
    }
    if (npesCaught == 3)
        out.println(JSFTestUtil.PASS);
}
Also used : FacesContext(jakarta.faces.context.FacesContext) ContextCallback(jakarta.faces.component.ContextCallback) UIComponent(jakarta.faces.component.UIComponent) UIForm(jakarta.faces.component.UIForm) UIViewRoot(jakarta.faces.component.UIViewRoot) ServletException(jakarta.servlet.ServletException) FacesException(jakarta.faces.FacesException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) UIData(jakarta.faces.component.UIData)

Example 20 with UIForm

use of jakarta.faces.component.UIForm in project faces by jakartaee.

the class TestServlet method createForm.

protected UIComponent createForm(boolean submitted) {
    UIForm form = new UIForm();
    form.setSubmitted(submitted);
    return form;
}
Also used : UIForm(jakarta.faces.component.UIForm)

Aggregations

UIForm (jakarta.faces.component.UIForm)56 UIComponent (jakarta.faces.component.UIComponent)19 UIViewRoot (jakarta.faces.component.UIViewRoot)15 PrintWriter (java.io.PrintWriter)14 UIOutput (jakarta.faces.component.UIOutput)10 UIInput (jakarta.faces.component.UIInput)8 ClientBehaviorHolder (jakarta.faces.component.behavior.ClientBehaviorHolder)7 FacesContext (jakarta.faces.context.FacesContext)7 ResponseWriter (jakarta.faces.context.ResponseWriter)7 Test (org.junit.Test)7 List (java.util.List)5 UICommand (jakarta.faces.component.UICommand)4 HtmlCommandLink (jakarta.faces.component.html.HtmlCommandLink)4 VisitHint (jakarta.faces.component.visit.VisitHint)4 Locale (java.util.Locale)4 Map (java.util.Map)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 ViewPoolProcessor (org.apache.myfaces.view.facelets.ViewPoolProcessor)4 FacesException (jakarta.faces.FacesException)3 FacesMessage (jakarta.faces.application.FacesMessage)3