Search in sources :

Example 1 with HtmlInputSecret

use of jakarta.faces.component.html.HtmlInputSecret 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);
}
Also used : HtmlSelectBooleanCheckbox(jakarta.faces.component.html.HtmlSelectBooleanCheckbox) HtmlInputTextarea(jakarta.faces.component.html.HtmlInputTextarea) HtmlInputFile(jakarta.faces.component.html.HtmlInputFile) HtmlSelectOneListbox(jakarta.faces.component.html.HtmlSelectOneListbox) HtmlCommandLink(jakarta.faces.component.html.HtmlCommandLink) HtmlOutcomeTargetLink(jakarta.faces.component.html.HtmlOutcomeTargetLink) HtmlGraphicImage(jakarta.faces.component.html.HtmlGraphicImage) UIComponent(jakarta.faces.component.UIComponent) HtmlInputText(jakarta.faces.component.html.HtmlInputText) UIForm(jakarta.faces.component.UIForm) HtmlCommandButton(jakarta.faces.component.html.HtmlCommandButton) HtmlOutputLabel(jakarta.faces.component.html.HtmlOutputLabel) HtmlInputSecret(jakarta.faces.component.html.HtmlInputSecret) HtmlHead(jakarta.faces.component.html.HtmlHead) HtmlBody(jakarta.faces.component.html.HtmlBody) UIOutput(jakarta.faces.component.UIOutput) HtmlSelectManyListbox(jakarta.faces.component.html.HtmlSelectManyListbox) HtmlOutputLink(jakarta.faces.component.html.HtmlOutputLink) UIViewRoot(jakarta.faces.component.UIViewRoot) HtmlOutcomeTargetButton(jakarta.faces.component.html.HtmlOutcomeTargetButton) HtmlInputHidden(jakarta.faces.component.html.HtmlInputHidden)

Example 2 with HtmlInputSecret

use of jakarta.faces.component.html.HtmlInputSecret in project myfaces by apache.

the class HtmlSecretRendererBase method renderInputBegin.

// Subclasses can set the value of an attribute before, or can render a custom attribute after calling this method
protected void renderInputBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    ResponseWriter writer = facesContext.getResponseWriter();
    writer.startElement(HTML.INPUT_ELEM, uiComponent);
    writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_PASSWORD, null);
    if (uiComponent instanceof ClientBehaviorHolder && !((ClientBehaviorHolder) uiComponent).getClientBehaviors().isEmpty()) {
        writer.writeAttribute(HTML.ID_ATTR, uiComponent.getClientId(facesContext), null);
    } else {
        HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext);
    }
    writer.writeAttribute(HTML.NAME_ATTR, uiComponent.getClientId(facesContext), null);
    boolean isRedisplay;
    if (uiComponent instanceof HtmlInputSecret) {
        isRedisplay = ((HtmlInputSecret) uiComponent).isRedisplay();
    } else {
        isRedisplay = AttributeUtils.getBooleanAttribute(uiComponent, ComponentAttrs.REDISPLAY_ATTR, false);
    }
    if (isRedisplay) {
        String strValue = RendererUtils.getStringValue(facesContext, uiComponent);
        writer.writeAttribute(HTML.VALUE_ATTR, strValue, ComponentAttrs.VALUE_ATTR);
    }
    if (uiComponent instanceof ClientBehaviorHolder) {
        Map<String, List<ClientBehavior>> 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, behaviors);
            if (isCommonEventsOptimizationEnabled(facesContext)) {
                Long commonEventsMarked = CommonHtmlEventsUtil.getMarkedEvents(uiComponent);
                CommonHtmlEventsUtil.renderBehaviorizedEventHandlers(facesContext, writer, commonPropertiesMarked, commonEventsMarked, uiComponent, behaviors);
                CommonHtmlEventsUtil.renderBehaviorizedFieldEventHandlersWithoutOnchange(facesContext, writer, commonPropertiesMarked, commonEventsMarked, uiComponent, behaviors);
            } else {
                HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, uiComponent, behaviors);
                HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchange(facesContext, writer, uiComponent, behaviors);
            }
        }
        if (isCommonPropertiesOptimizationEnabled(facesContext)) {
            CommonHtmlAttributesUtil.renderInputPassthroughPropertiesWithoutDisabledAndEvents(writer, commonPropertiesMarked, uiComponent);
        } else {
            HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_EVENTS);
        }
    } else {
        if (isCommonPropertiesOptimizationEnabled(facesContext)) {
            CommonHtmlAttributesUtil.renderInputPassthroughPropertiesWithoutDisabled(writer, CommonHtmlAttributesUtil.getMarkedAttributes(uiComponent), uiComponent);
        } else {
            HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED);
        }
    }
    if (isDisabled(facesContext, uiComponent)) {
        writer.writeAttribute(HTML.DISABLED_ATTR, HTML.DISABLED_ATTR, null);
    }
    if (isAutocompleteOff(facesContext, uiComponent)) {
        writer.writeAttribute(HTML.AUTOCOMPLETE_ATTR, AUTOCOMPLETE_VALUE_OFF, HTML.AUTOCOMPLETE_ATTR);
    }
}
Also used : ResponseWriter(jakarta.faces.context.ResponseWriter) List(java.util.List) ClientBehaviorHolder(jakarta.faces.component.behavior.ClientBehaviorHolder) HtmlInputSecret(jakarta.faces.component.html.HtmlInputSecret)

Example 3 with HtmlInputSecret

use of jakarta.faces.component.html.HtmlInputSecret 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);
}
Also used : HtmlSelectBooleanCheckbox(jakarta.faces.component.html.HtmlSelectBooleanCheckbox) HtmlInputTextarea(jakarta.faces.component.html.HtmlInputTextarea) HtmlInputFile(jakarta.faces.component.html.HtmlInputFile) HtmlSelectOneListbox(jakarta.faces.component.html.HtmlSelectOneListbox) HtmlCommandLink(jakarta.faces.component.html.HtmlCommandLink) HtmlOutcomeTargetLink(jakarta.faces.component.html.HtmlOutcomeTargetLink) HtmlGraphicImage(jakarta.faces.component.html.HtmlGraphicImage) UIComponent(jakarta.faces.component.UIComponent) HtmlInputText(jakarta.faces.component.html.HtmlInputText) UIForm(jakarta.faces.component.UIForm) HtmlCommandButton(jakarta.faces.component.html.HtmlCommandButton) HtmlOutputLabel(jakarta.faces.component.html.HtmlOutputLabel) HtmlInputSecret(jakarta.faces.component.html.HtmlInputSecret) HtmlHead(jakarta.faces.component.html.HtmlHead) HtmlBody(jakarta.faces.component.html.HtmlBody) UIOutput(jakarta.faces.component.UIOutput) HtmlSelectManyListbox(jakarta.faces.component.html.HtmlSelectManyListbox) HtmlOutputLink(jakarta.faces.component.html.HtmlOutputLink) UIViewRoot(jakarta.faces.component.UIViewRoot) HtmlOutcomeTargetButton(jakarta.faces.component.html.HtmlOutcomeTargetButton) HtmlInputHidden(jakarta.faces.component.html.HtmlInputHidden)

Example 4 with HtmlInputSecret

use of jakarta.faces.component.html.HtmlInputSecret in project myfaces by apache.

the class HtmlSecretRendererTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    inputText = new HtmlInputSecret();
    writer = new MockResponseWriter(new StringWriter(), null, null);
    facesContext.setResponseWriter(writer);
    facesContext.getViewRoot().setRenderKitId(MockRenderKitFactory.HTML_BASIC_RENDER_KIT);
    facesContext.getRenderKit().addRenderer(inputText.getFamily(), inputText.getRendererType(), new HtmlSecretRenderer());
    facesContext.getAttributes().put("org.apache.myfaces.RENDERED_FACES_JS", Boolean.TRUE);
}
Also used : StringWriter(java.io.StringWriter) MockResponseWriter(org.apache.myfaces.test.mock.MockResponseWriter) HtmlInputSecret(jakarta.faces.component.html.HtmlInputSecret)

Aggregations

HtmlInputSecret (jakarta.faces.component.html.HtmlInputSecret)4 UIComponent (jakarta.faces.component.UIComponent)2 UIForm (jakarta.faces.component.UIForm)2 UIOutput (jakarta.faces.component.UIOutput)2 UIViewRoot (jakarta.faces.component.UIViewRoot)2 HtmlBody (jakarta.faces.component.html.HtmlBody)2 HtmlCommandButton (jakarta.faces.component.html.HtmlCommandButton)2 HtmlCommandLink (jakarta.faces.component.html.HtmlCommandLink)2 HtmlGraphicImage (jakarta.faces.component.html.HtmlGraphicImage)2 HtmlHead (jakarta.faces.component.html.HtmlHead)2 HtmlInputFile (jakarta.faces.component.html.HtmlInputFile)2 HtmlInputHidden (jakarta.faces.component.html.HtmlInputHidden)2 HtmlInputText (jakarta.faces.component.html.HtmlInputText)2 HtmlInputTextarea (jakarta.faces.component.html.HtmlInputTextarea)2 HtmlOutcomeTargetButton (jakarta.faces.component.html.HtmlOutcomeTargetButton)2 HtmlOutcomeTargetLink (jakarta.faces.component.html.HtmlOutcomeTargetLink)2 HtmlOutputLabel (jakarta.faces.component.html.HtmlOutputLabel)2 HtmlOutputLink (jakarta.faces.component.html.HtmlOutputLink)2 HtmlSelectBooleanCheckbox (jakarta.faces.component.html.HtmlSelectBooleanCheckbox)2 HtmlSelectManyListbox (jakarta.faces.component.html.HtmlSelectManyListbox)2