use of jakarta.faces.component.html.HtmlOutputLink 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.html.HtmlOutputLink in project myfaces by apache.
the class HtmlLinkRendererBase method renderOutputLinkStart.
protected void renderOutputLinkStart(FacesContext facesContext, UIOutput output) throws IOException {
ResponseWriter writer = facesContext.getResponseWriter();
Map<String, List<ClientBehavior>> behaviors = null;
if (HtmlRendererUtils.isDisabled(output)) {
writer.startElement(HTML.SPAN_ELEM, output);
if (output instanceof ClientBehaviorHolder) {
behaviors = ((ClientBehaviorHolder) output).getClientBehaviors();
if (!behaviors.isEmpty()) {
HtmlRendererUtils.writeIdAndName(writer, output, facesContext);
} else {
HtmlRendererUtils.writeIdIfNecessary(writer, output, facesContext);
}
long commonPropertiesMarked = 0L;
if (isCommonPropertiesOptimizationEnabled(facesContext)) {
commonPropertiesMarked = CommonHtmlAttributesUtil.getMarkedAttributes(output);
}
if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext)) {
CommonHtmlAttributesUtil.renderEventProperties(writer, commonPropertiesMarked, output);
CommonHtmlAttributesUtil.renderFocusBlurEventProperties(writer, commonPropertiesMarked, output);
} else {
if (isCommonEventsOptimizationEnabled(facesContext)) {
Long commonEventsMarked = CommonHtmlEventsUtil.getMarkedEvents(output);
CommonHtmlEventsUtil.renderBehaviorizedEventHandlers(facesContext, writer, commonPropertiesMarked, commonEventsMarked, output, behaviors);
CommonHtmlEventsUtil.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(facesContext, writer, commonPropertiesMarked, commonEventsMarked, output, behaviors);
} else {
HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, output, behaviors);
HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(facesContext, writer, output, behaviors);
}
}
if (isCommonPropertiesOptimizationEnabled(facesContext)) {
CommonHtmlAttributesUtil.renderAnchorPassthroughPropertiesDisabledWithoutEvents(writer, commonPropertiesMarked, output);
} else {
HtmlRendererUtils.renderHTMLAttributes(writer, output, HTML.ANCHOR_PASSTHROUGH_ATTRIBUTES_DISABLED_WITHOUT_EVENTS);
}
} else {
HtmlRendererUtils.writeIdIfNecessary(writer, output, facesContext);
if (isCommonPropertiesOptimizationEnabled(facesContext)) {
CommonHtmlAttributesUtil.renderAnchorPassthroughPropertiesDisabled(writer, CommonHtmlAttributesUtil.getMarkedAttributes(output), output);
} else {
HtmlRendererUtils.renderHTMLAttributes(writer, output, HTML.ANCHOR_PASSTHROUGH_ATTRIBUTES_DISABLED);
}
}
} else {
// calculate href
String href = RendererUtils.getStringValue(facesContext, output);
// check if there is an anchor # in it
int index = href.indexOf('#');
String anchorString = null;
boolean isAnchorInHref = (index > -1);
if (isAnchorInHref) {
// remove anchor element and add it again after the parameter are encoded
anchorString = href.substring(index, href.length());
href = href.substring(0, index);
}
if (getChildCount(output) > 0) {
StringBuilder hrefBuf = new StringBuilder(href);
addChildParametersToHref(facesContext, output, hrefBuf, // first url parameter?
(href.indexOf('?') == -1), writer.getCharacterEncoding());
href = hrefBuf.toString();
}
// check for the fragement attribute
String fragmentAttr = null;
if (output instanceof HtmlOutputLink) {
fragmentAttr = ((HtmlOutputLink) output).getFragment();
} else {
fragmentAttr = (String) output.getAttributes().get(ComponentAttrs.FRAGMENT_ATTR);
}
if (fragmentAttr != null && !fragmentAttr.isEmpty()) {
href += '#' + fragmentAttr;
} else if (isAnchorInHref) {
href += anchorString;
}
// TODO: or encodeActionURL ?
href = facesContext.getExternalContext().encodeResourceURL(href);
// write anchor
writer.startElement(HTML.ANCHOR_ELEM, output);
writer.writeURIAttribute(HTML.HREF_ATTR, href, null);
if (output instanceof ClientBehaviorHolder) {
behaviors = ((ClientBehaviorHolder) output).getClientBehaviors();
if (!behaviors.isEmpty()) {
HtmlRendererUtils.writeIdAndName(writer, output, facesContext);
} else {
HtmlRendererUtils.writeIdAndNameIfNecessary(writer, output, facesContext);
}
long commonPropertiesMarked = 0L;
if (isCommonPropertiesOptimizationEnabled(facesContext)) {
commonPropertiesMarked = CommonHtmlAttributesUtil.getMarkedAttributes(output);
}
if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext)) {
CommonHtmlAttributesUtil.renderEventProperties(writer, commonPropertiesMarked, output);
CommonHtmlAttributesUtil.renderFocusBlurEventProperties(writer, commonPropertiesMarked, output);
} else {
if (isCommonEventsOptimizationEnabled(facesContext)) {
Long commonEventsMarked = CommonHtmlEventsUtil.getMarkedEvents(output);
CommonHtmlEventsUtil.renderBehaviorizedEventHandlers(facesContext, writer, commonPropertiesMarked, commonEventsMarked, output, behaviors);
CommonHtmlEventsUtil.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(facesContext, writer, commonPropertiesMarked, commonEventsMarked, output, behaviors);
} else {
HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, output, behaviors);
HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(facesContext, writer, output, behaviors);
}
}
if (isCommonPropertiesOptimizationEnabled(facesContext)) {
CommonHtmlAttributesUtil.renderAnchorPassthroughPropertiesWithoutEvents(writer, commonPropertiesMarked, output);
} else {
HtmlRendererUtils.renderHTMLAttributes(writer, output, HTML.ANCHOR_PASSTHROUGH_ATTRIBUTES_WITHOUT_EVENTS);
}
} else {
HtmlRendererUtils.writeIdAndNameIfNecessary(writer, output, facesContext);
if (isCommonPropertiesOptimizationEnabled(facesContext)) {
CommonHtmlAttributesUtil.renderAnchorPassthroughProperties(writer, CommonHtmlAttributesUtil.getMarkedAttributes(output), output);
} else {
HtmlRendererUtils.renderHTMLAttributes(writer, output, HTML.ANCHOR_PASSTHROUGH_ATTRIBUTES);
}
}
writer.flush();
}
}
use of jakarta.faces.component.html.HtmlOutputLink in project myfaces by apache.
the class DefaultHtmlDecoratorTestCase 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.html.HtmlOutputLink in project myfaces by apache.
the class HtmlLinkRendererTest method setUp.
public void setUp() throws Exception {
super.setUp();
UIForm form = new UIForm();
commandLink = new HtmlCommandLink();
outputLink = new HtmlOutputLink();
outputLink.setValue("http://someurl");
outcomeTargetLink = new HtmlOutcomeTargetLink();
form.getChildren().add(commandLink);
writer = new MockResponseWriter(new StringWriter(), null, "UTF-8");
facesContext.setResponseWriter(writer);
facesContext.getApplication().setNavigationHandler(new NavigationHandlerImpl());
facesContext.getViewRoot().setRenderKitId(MockRenderKitFactory.HTML_BASIC_RENDER_KIT);
facesContext.getRenderKit().addRenderer(commandLink.getFamily(), commandLink.getRendererType(), new HtmlLinkRenderer());
facesContext.getRenderKit().addRenderer(form.getFamily(), form.getRendererType(), new HtmlFormRenderer());
facesContext.getRenderKit().addRenderer(outputLink.getFamily(), outputLink.getRendererType(), new HtmlLinkRenderer());
facesContext.getRenderKit().addRenderer(outcomeTargetLink.getFamily(), outcomeTargetLink.getRendererType(), new HtmlLinkRenderer());
facesContext.getAttributes().put("org.apache.myfaces.RENDERED_FACES_JS", Boolean.TRUE);
}
Aggregations