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;
}
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);
}
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);
}
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);
}
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;
}
Aggregations