use of jakarta.faces.component.UIForm in project myfaces by apache.
the class HtmlRadioRendererBase method renderRadio.
/**
* Renders the input item
* @return the 'id' value of the rendered element
*/
protected String renderRadio(FacesContext facesContext, UIInput uiComponent, String value, boolean disabled, boolean checked, boolean renderId, Integer itemNum) throws IOException {
String clientId = uiComponent.getClientId(facesContext);
String itemId = (itemNum == null) ? null : clientId + facesContext.getNamingContainerSeparatorChar() + itemNum;
ResponseWriter writer = facesContext.getResponseWriter();
writer.startElement(HTML.INPUT_ELEM, uiComponent);
if (itemId != null) {
writer.writeAttribute(HTML.ID_ATTR, itemId, null);
} else if (renderId) {
writer.writeAttribute(HTML.ID_ATTR, clientId, null);
}
writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_RADIO, null);
String group = uiComponent instanceof HtmlSelectOneRadio ? ((HtmlSelectOneRadio) uiComponent).getGroup() : null;
if (group != null && !group.isEmpty()) {
UIForm form = ComponentUtils.findClosest(UIForm.class, uiComponent);
writer.writeAttribute(HTML.NAME_ATTR, form.getClientId(facesContext) + facesContext.getNamingContainerSeparatorChar() + group, null);
} else {
writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
}
if (disabled) {
writer.writeAttribute(HTML.DISABLED_ATTR, HTML.DISABLED_ATTR, null);
}
if (checked) {
writer.writeAttribute(HTML.CHECKED_ATTR, HTML.CHECKED_ATTR, null);
}
if (group != null && group.length() > 0) {
if (value != null) {
writer.writeAttribute(HTML.VALUE_ATTR, clientId + facesContext.getNamingContainerSeparatorChar() + value, null);
} else {
writer.writeAttribute(HTML.VALUE_ATTR, clientId + facesContext.getNamingContainerSeparatorChar() + "", null);
}
} else {
if (value != null) {
writer.writeAttribute(HTML.VALUE_ATTR, value, null);
} else {
writer.writeAttribute(HTML.VALUE_ATTR, "", null);
}
}
Map<String, List<ClientBehavior>> behaviors = null;
if (uiComponent instanceof ClientBehaviorHolder) {
behaviors = ((ClientBehaviorHolder) uiComponent).getClientBehaviors();
long commonPropertiesMarked = 0L;
if (isCommonPropertiesOptimizationEnabled(facesContext)) {
commonPropertiesMarked = CommonHtmlAttributesUtil.getMarkedAttributes(uiComponent);
}
if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext)) {
CommonHtmlAttributesUtil.renderChangeEventProperty(writer, commonPropertiesMarked, uiComponent);
CommonHtmlAttributesUtil.renderEventProperties(writer, commonPropertiesMarked, uiComponent);
CommonHtmlAttributesUtil.renderFieldEventPropertiesWithoutOnchange(writer, commonPropertiesMarked, uiComponent);
} else {
HtmlRendererUtils.renderBehaviorizedOnchangeEventHandler(facesContext, writer, uiComponent, itemId != null ? itemId : clientId, behaviors);
if (isCommonEventsOptimizationEnabled(facesContext)) {
Long commonEventsMarked = CommonHtmlEventsUtil.getMarkedEvents(uiComponent);
CommonHtmlEventsUtil.renderBehaviorizedEventHandlers(facesContext, writer, commonPropertiesMarked, commonEventsMarked, uiComponent, itemId != null ? itemId : clientId, behaviors);
CommonHtmlEventsUtil.renderBehaviorizedFieldEventHandlersWithoutOnchange(facesContext, writer, commonPropertiesMarked, commonEventsMarked, uiComponent, itemId != null ? itemId : clientId, behaviors);
} else {
HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, uiComponent, itemId != null ? itemId : clientId, behaviors);
HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchange(facesContext, writer, uiComponent, itemId != null ? itemId : clientId, behaviors);
}
}
HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_STYLE_AND_EVENTS);
} else {
HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_STYLE);
}
if (isDisabled(facesContext, uiComponent)) {
writer.writeAttribute(HTML.DISABLED_ATTR, HTML.DISABLED_ATTR, null);
}
writer.endElement(HTML.INPUT_ELEM);
return itemId;
}
use of jakarta.faces.component.UIForm in project myfaces by apache.
the class DefaultHtmlDecoratorTestCaseUrn method checkTags.
private void checkTags() throws Exception {
UIViewRoot root = facesContext.getViewRoot();
HtmlHead head = (HtmlHead) root.findComponent("idHead");
int linksFound = 0;
int scriptsFound = 0;
for (UIComponent child : head.getChildren()) {
if (child instanceof UIOutput) {
if (ResourceUtils.DEFAULT_SCRIPT_RENDERER_TYPE.equals(child.getRendererType())) {
Assert.assertEquals("osc", child.getId());
scriptsFound++;
}
if (ResourceUtils.DEFAULT_STYLESHEET_RENDERER_TYPE.equals(child.getRendererType())) {
Assert.assertEquals("osh", child.getId());
linksFound++;
}
}
}
for (UIComponent child : root.getComponentResources(facesContext, "head")) {
if ("jakarta.faces.resource.Stylesheet".equals(child.getRendererType())) {
Assert.assertEquals("osh", child.getId());
linksFound++;
}
}
Assert.assertEquals(1, linksFound);
Assert.assertEquals(1, scriptsFound);
HtmlBody body = (HtmlBody) root.findComponent("idBody");
Assert.assertNotNull(body);
UIForm form = (UIForm) root.findComponent("myForm");
Assert.assertNotNull(form);
HtmlCommandLink link1 = (HtmlCommandLink) form.findComponent("link1");
Assert.assertNotNull(link1);
Assert.assertEquals("#{test.testAction}", link1.getActionExpression().getExpressionString());
HtmlCommandLink link2 = (HtmlCommandLink) form.findComponent("link2");
Assert.assertNotNull(link2);
Assert.assertEquals(1, link2.getActionListeners().length);
HtmlOutputLink link3 = (HtmlOutputLink) form.findComponent("link3");
Assert.assertNotNull(link3);
Assert.assertEquals("/my/new/location.txt", link3.getValue());
HtmlOutcomeTargetLink link4 = (HtmlOutcomeTargetLink) form.findComponent("link4");
Assert.assertNotNull(link4);
Assert.assertEquals("rollback", link4.getOutcome());
HtmlCommandButton button = (HtmlCommandButton) form.findComponent("button1");
Assert.assertNotNull(button);
Assert.assertEquals("#{test.testAction}", button.getActionExpression().getExpressionString());
HtmlOutcomeTargetButton button2 = (HtmlOutcomeTargetButton) form.findComponent("button2");
Assert.assertNotNull(button2);
Assert.assertEquals("rollback", button2.getOutcome());
HtmlGraphicImage img1 = (HtmlGraphicImage) form.findComponent("img1");
Assert.assertNotNull(img1);
Assert.assertEquals("/my/image.png", img1.getUrl());
HtmlCommandButton input1 = (HtmlCommandButton) form.findComponent("input1");
Assert.assertNotNull(input1);
HtmlSelectBooleanCheckbox input2 = (HtmlSelectBooleanCheckbox) form.findComponent("input2");
Assert.assertNotNull(input2);
HtmlInputText input3 = (HtmlInputText) form.findComponent("input3");
Assert.assertNotNull(input3);
HtmlInputText input4 = (HtmlInputText) form.findComponent("input4");
Assert.assertNotNull(input4);
HtmlInputText input5 = (HtmlInputText) form.findComponent("input5");
Assert.assertNotNull(input5);
HtmlInputText input6 = (HtmlInputText) form.findComponent("input6");
Assert.assertNotNull(input6);
HtmlInputText input7 = (HtmlInputText) form.findComponent("input7");
Assert.assertNotNull(input7);
HtmlInputText input8 = (HtmlInputText) form.findComponent("input8");
Assert.assertNotNull(input8);
HtmlInputText input9 = (HtmlInputText) form.findComponent("input9");
Assert.assertNotNull(input9);
HtmlInputText input10 = (HtmlInputText) form.findComponent("input10");
Assert.assertNotNull(input10);
HtmlInputText input11 = (HtmlInputText) form.findComponent("input11");
Assert.assertNotNull(input11);
HtmlInputText input12 = (HtmlInputText) form.findComponent("input12");
Assert.assertNotNull(input12);
HtmlInputText input13 = (HtmlInputText) form.findComponent("input13");
Assert.assertNotNull(input13);
HtmlInputText input14 = (HtmlInputText) form.findComponent("input14");
Assert.assertNotNull(input14);
HtmlInputFile input15 = (HtmlInputFile) form.findComponent("input15");
Assert.assertNotNull(input15);
HtmlInputHidden input16 = (HtmlInputHidden) form.findComponent("input16");
Assert.assertNotNull(input16);
HtmlInputSecret input17 = (HtmlInputSecret) form.findComponent("input17");
Assert.assertNotNull(input17);
HtmlCommandButton input18 = (HtmlCommandButton) form.findComponent("input18");
Assert.assertNotNull(input18);
HtmlCommandButton input19 = (HtmlCommandButton) form.findComponent("input19");
Assert.assertNotNull(input19);
HtmlInputText input20 = (HtmlInputText) form.findComponent("input20");
Assert.assertNotNull(input20);
HtmlOutputLabel label1 = (HtmlOutputLabel) form.findComponent("label1");
Assert.assertNotNull(label1);
HtmlSelectOneListbox select1 = (HtmlSelectOneListbox) form.findComponent("select1");
Assert.assertNotNull(select1);
HtmlSelectManyListbox select2 = (HtmlSelectManyListbox) form.findComponent("select2");
Assert.assertNotNull(select2);
HtmlInputTextarea textarea1 = (HtmlInputTextarea) form.findComponent("textarea1");
Assert.assertNotNull(textarea1);
}
use of jakarta.faces.component.UIForm in project mojarra by eclipse-ee4j.
the class WholeBeanValidator method validate.
public void validate(FacesContext context, UIValidateWholeBean component, Object value) throws ValidatorException {
// Get parent and check if the parent of this f:validateWholeBean is a form
UIForm form = getParentForm(component);
ValueExpression wholeBeanVE = getValueExpressionNullSafe(component, "value");
// The "whole" bean that we're going to validate at the class level
Object wholeBean = wholeBeanVE.getValue(context.getELContext());
// A shortened or fully qualified class name, or EL expression pointing
// to a type that copies the target bean for validation
String copierType = (String) component.getAttributes().get("copierType");
// Inspect the status of field level validation
if (hasAnyBeanPropertyFailedValidation(context, wholeBean)) {
return;
}
AddRemainingCandidateFieldsCallback addRemainingCandidateFieldsCallback = new AddRemainingCandidateFieldsCallback(context, wholeBean);
form.visitTree(createVisitContext(context), addRemainingCandidateFieldsCallback);
Map<String, Map<String, Object>> validationCandidate = addRemainingCandidateFieldsCallback.getCandidate();
if (validationCandidate.isEmpty()) {
return;
}
// Perform the actual bean validation on a copy of the whole bean
Set<ConstraintViolation<?>> violations = doBeanValidation(getBeanValidator(context), copyBeanAndPopulateWithCandidateValues(context, wholeBeanVE, wholeBean, copierType, validationCandidate), component.getValidationGroupsArray(), wholeBeanVE);
// If there are any violations, transform them into a Faces validator exception
if (violations != null && !violations.isEmpty()) {
ValidatorException toThrow;
if (violations.size() == 1) {
ConstraintViolation<?> violation = violations.iterator().next();
toThrow = new ValidatorException(getMessage(context, MESSAGE_ID, violation.getMessage(), getLabel(context, component)));
} else {
Set<FacesMessage> messages = new LinkedHashSet<>(violations.size());
for (ConstraintViolation<?> violation : violations) {
messages.add(getMessage(context, MESSAGE_ID, violation.getMessage(), getLabel(context, component)));
}
toThrow = new ValidatorException(messages);
}
// values during updateModelValues
for (Entry<String, Map<String, Object>> validationCandidateEntry : validationCandidate.entrySet()) {
invalidateComponent(validationCandidateEntry);
}
throw toThrow;
}
}
use of jakarta.faces.component.UIForm in project faces by jakartaee.
the class BaseUIComponentTestServlet method setupInvokeOnComponentTree.
// ------------------------------------------------------------- Private
// Methods
/**
* Comments to come later.
*/
private Map<String, UIComponent> setupInvokeOnComponentTree() {
UIViewRoot root = new UIViewRoot();
UIForm form1 = new UIForm();
UIPanel panel1 = new UIPanel();
UIInput input1 = new UIInput();
UIInput input2 = new UIInput();
UIForm form2 = new UIForm();
UIPanel panel2 = new UIPanel();
UIInput input3 = new UIInput();
UIInput input4 = new UIInput();
root.setId("root");
form1.setId("form1");
panel1.setId("panel1");
input1.setId("input1");
input2.setId("input2");
form2.setId("form2");
panel2.setId("panel2");
input3.setId("input1");
input4.setId("input2");
root.getChildren().add(form1);
form1.getChildren().add(panel1);
panel1.getChildren().add(input1);
panel1.getChildren().add(input2);
root.getChildren().add(form2);
form2.getChildren().add(panel2);
panel2.getChildren().add(input3);
panel2.getChildren().add(input4);
Map<String, UIComponent> result = new HashMap<String, UIComponent>();
result.put("root", root);
result.put("form1", form1);
result.put("panel1", panel1);
result.put("input1", input1);
result.put("input2", input2);
result.put("form2", form2);
result.put("panel2", panel2);
result.put("input3", input3);
result.put("input4", input4);
return result;
}
use of jakarta.faces.component.UIForm in project faces by jakartaee.
the class BaseUIComponentTestServlet method uiComponentFindComponentTest.
// UIComponent.findComponent()
public void uiComponentFindComponentTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Set up a component hierarchy as follows (component ids in quotes)");
out.println("\"a\" - UIViewRoot at head of hierarchy");
out.println("\"a\" has children \"b\" and \"c\"");
out.println("\"b\" has children \"d\" and \"g\"");
out.println("d\" has children \"e\" and \"f\"");
out.println("\"c\" has children \"h\" and \"i\"");
out.println("Components \"b\" and \"d\" implement NamingContainer");
UIViewRoot a = createViewRoot();
a.setId("a");
UIForm b = new UIForm();
b.setId("b");
UIPanel c = new UIPanel();
c.setId("c");
UINamingContainer d = new UINamingContainer();
d.setId("d");
UIPanel e = new UIPanel();
e.setId("e");
UIPanel f = new UIPanel();
f.setId("f");
UIPanel g = new UIPanel();
g.setId("g");
UIPanel h = new UIPanel();
h.setId("h");
UIPanel i = new UIPanel();
i.setId("i");
a.getChildren().add(b);
a.getChildren().add(c);
b.getChildren().add(d);
b.getChildren().add(g);
c.getChildren().add(h);
c.getChildren().add(i);
d.getChildren().add(e);
d.getChildren().add(f);
StringBuffer buf = new StringBuffer(128);
// Positive relative searches from "a"
assertFound(a, a, "a", buf);
assertFound(a, b, "b", buf);
assertFound(a, c, "c", buf);
assertFound(a, d, "b:d", buf);
assertFound(a, e, "b:d:e", buf);
assertFound(a, f, "b:d:f", buf);
assertFound(a, g, "b:g", buf);
assertFound(a, h, "h", buf);
assertFound(a, i, "i", buf);
// Negative relative searches from "a"
assertNotFound(a, "d", buf);
assertNotFound(a, "e", buf);
assertNotFound(a, "f", buf);
assertNotFound(a, "g", buf);
// Positive relative searches from "b"
assertFound(b, b, "b", buf);
assertFound(b, d, "d", buf);
assertFound(b, e, "d:e", buf);
assertFound(b, f, "d:f", buf);
assertFound(b, g, "g", buf);
// Negative relative searches from "b"
assertNotFound(b, "a", buf);
assertNotFound(b, "c", buf);
assertNotFound(b, "e", buf);
assertNotFound(b, "f", buf);
assertNotFound(b, "h", buf);
assertNotFound(b, "i", buf);
// Positive relative searches from "c"
assertFound(c, a, "a", buf);
assertFound(c, b, "b", buf);
assertFound(c, c, "c", buf);
assertFound(c, d, "b:d", buf);
assertFound(c, e, "b:d:e", buf);
assertFound(c, f, "b:d:f", buf);
assertFound(c, g, "b:g", buf);
assertFound(c, h, "h", buf);
assertFound(c, i, "i", buf);
// Negative relative searches from "c"
assertNotFound(c, "d", buf);
assertNotFound(c, "e", buf);
assertNotFound(c, "f", buf);
assertNotFound(c, "g", buf);
// Positive relative searches from "d"
assertFound(d, d, "d", buf);
assertFound(d, e, "e", buf);
assertFound(d, f, "f", buf);
// Negative relative searches from "d"
assertNotFound(d, "a", buf);
assertNotFound(d, "b", buf);
assertNotFound(d, "c", buf);
assertNotFound(d, "g", buf);
assertNotFound(d, "h", buf);
assertNotFound(d, "i", buf);
// Positive relative searches from "e"
assertFound(e, d, "d", buf);
assertFound(e, e, "e", buf);
assertFound(e, f, "f", buf);
// Negative relative searches from "e"
assertNotFound(e, "a", buf);
assertNotFound(e, "b", buf);
assertNotFound(e, "c", buf);
assertNotFound(e, "g", buf);
assertNotFound(e, "h", buf);
assertNotFound(e, "i", buf);
// Positive relative searches from "f"
assertFound(f, d, "d", buf);
assertFound(f, e, "e", buf);
assertFound(f, f, "f", buf);
// Negative relative searches from "f"
assertNotFound(f, "a", buf);
assertNotFound(f, "b", buf);
assertNotFound(f, "c", buf);
assertNotFound(f, "g", buf);
assertNotFound(f, "h", buf);
assertNotFound(f, "i", buf);
// Positive relative searches from "g"
assertFound(g, b, "b", buf);
assertFound(g, d, "d", buf);
assertFound(g, e, "d:e", buf);
assertFound(g, f, "d:f", buf);
assertFound(g, g, "g", buf);
// Negative relative searches from "g"
assertNotFound(g, "a", buf);
assertNotFound(g, "c", buf);
assertNotFound(g, "e", buf);
assertNotFound(g, "f", buf);
assertNotFound(g, "h", buf);
assertNotFound(g, "i", buf);
// Positive relative searches from "h"
assertFound(h, a, "a", buf);
assertFound(h, b, "b", buf);
assertFound(h, c, "c", buf);
assertFound(h, d, "b:d", buf);
assertFound(h, e, "b:d:e", buf);
assertFound(h, f, "b:d:f", buf);
assertFound(h, g, "b:g", buf);
assertFound(h, h, "h", buf);
assertFound(h, i, "i", buf);
// Negative relative searches from "h"
assertNotFound(h, "d", buf);
assertNotFound(h, "e", buf);
assertNotFound(h, "f", buf);
assertNotFound(h, "g", buf);
// Positive relative searches from "i"
assertFound(i, a, "a", buf);
assertFound(i, b, "b", buf);
assertFound(i, c, "c", buf);
assertFound(i, d, "b:d", buf);
assertFound(i, e, "b:d:e", buf);
assertFound(i, f, "b:d:f", buf);
assertFound(i, g, "b:g", buf);
assertFound(i, h, "h", buf);
assertFound(i, i, "i", buf);
// Negative relative searches from "i"
assertNotFound(i, "d", buf);
assertNotFound(i, "e", buf);
assertNotFound(i, "f", buf);
assertNotFound(i, "g", buf);
// Absolute searches from a - i
UIComponent[] comps = { a, b, c, d, e, f, g, h, i };
String[] exprs = { ":a", ":b", ":c", ":b:d", ":b:d:e", ":b:d:f", ":b:g", ":h", ":i" };
for (int ii = 0; ii < comps.length; ii++) {
UIComponent searchFrom = comps[ii];
for (int j = 0; j < comps.length; j++) {
assertFound(searchFrom, comps[j], exprs[j], buf);
}
}
if (buf.length() > 0) {
out.print(buf.toString());
} else {
out.println(JSFTestUtil.PASS);
}
}
Aggregations