Search in sources :

Example 21 with HtmlOutputText

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

the class CompositeComponentTestCase method testSimpleCompositeAttribute.

/**
 * Test simple attribute resolution (not set, default, normal use case).
 *
 * @throws Exception
 */
@Test
public void testSimpleCompositeAttribute() throws Exception {
    UIViewRoot root = facesContext.getViewRoot();
    vdl.buildView(facesContext, root, "testSimpleAttribute.xhtml");
    UIComponent panelGroup1 = root.findComponent("testGroup1");
    Assert.assertNotNull(panelGroup1);
    UINamingContainer compositeComponent1 = (UINamingContainer) panelGroup1.getChildren().get(0);
    Assert.assertNotNull(compositeComponent1);
    UIComponent facet1 = compositeComponent1.getFacet(UIComponent.COMPOSITE_FACET_NAME);
    Assert.assertNotNull(facet1);
    HtmlOutputText text1 = (HtmlOutputText) facet1.findComponent("text");
    Assert.assertNotNull(text1);
    compositeComponent1.pushComponentToEL(facesContext, compositeComponent1);
    facet1.pushComponentToEL(facesContext, facet1);
    text1.pushComponentToEL(facesContext, text1);
    // set on tag
    Assert.assertEquals("class1", text1.getStyleClass());
    // set as default
    Assert.assertEquals("background:red", text1.getStyle());
    // Check coercion of attribute using type value
    Assert.assertEquals(5, compositeComponent1.getAttributes().get("index"));
    // Check default coercion
    ValueExpression ve = facesContext.getApplication().getExpressionFactory().createValueExpression(facesContext.getELContext(), "#{cc.attrs.cols}", Object.class);
    Assert.assertEquals(1, (int) ve.getValue(facesContext.getELContext()));
    text1.popComponentFromEL(facesContext);
    facet1.popComponentFromEL(facesContext);
    compositeComponent1.popComponentFromEL(facesContext);
    UIComponent panelGroup2 = root.findComponent("testGroup2");
    Assert.assertNotNull(panelGroup2);
    UINamingContainer compositeComponent2 = (UINamingContainer) panelGroup2.getChildren().get(0);
    Assert.assertNotNull(compositeComponent2);
    UIComponent facet2 = compositeComponent2.getFacet(UIComponent.COMPOSITE_FACET_NAME);
    Assert.assertNotNull(facet2);
    HtmlOutputText text2 = (HtmlOutputText) facet2.findComponent("text");
    Assert.assertNotNull(text2);
    compositeComponent2.pushComponentToEL(facesContext, compositeComponent2);
    facet2.pushComponentToEL(facesContext, facet2);
    text2.pushComponentToEL(facesContext, text2);
    // set on tag
    Assert.assertEquals("background:green", text2.getStyle());
    // not set, should return null, but since there is a ValueExpression indirection,
    // coercing rules apply here, so null is converted as ""
    Assert.assertEquals("", text2.getStyleClass());
    text2.popComponentFromEL(facesContext);
    facet2.popComponentFromEL(facesContext);
    compositeComponent2.popComponentFromEL(facesContext);
    StringWriter sw = new StringWriter();
    MockResponseWriter mrw = new MockResponseWriter(sw);
    facesContext.setResponseWriter(mrw);
    compositeComponent1.encodeAll(facesContext);
    sw.flush();
    HtmlRenderedAttr[] attrs = new HtmlRenderedAttr[] { new HtmlRenderedAttr("style") };
    HtmlCheckAttributesUtil.checkRenderedAttributes(attrs, sw.toString());
}
Also used : StringWriter(java.io.StringWriter) ValueExpression(jakarta.el.ValueExpression) UIComponent(jakarta.faces.component.UIComponent) MockResponseWriter(org.apache.myfaces.test.mock.MockResponseWriter) UINamingContainer(jakarta.faces.component.UINamingContainer) HtmlOutputText(jakarta.faces.component.html.HtmlOutputText) HtmlRenderedAttr(org.apache.myfaces.test.utils.HtmlRenderedAttr) UIViewRoot(jakarta.faces.component.UIViewRoot) Test(org.junit.Test)

Example 22 with HtmlOutputText

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

the class CompositeComponentAttributeTestCase method testSimpleCompositeAttributeInsertChildren.

/**
 * Test simple attribute resolution (not set, default, normal use case).
 *
 * @throws Exception
 */
@Test
public void testSimpleCompositeAttributeInsertChildren() throws Exception {
    MockAttributeBean bean = new MockAttributeBean();
    facesContext.getExternalContext().getRequestMap().put("bean", bean);
    UIViewRoot root = facesContext.getViewRoot();
    vdl.buildView(facesContext, root, "testSimpleAttributeVEInsertChildren.xhtml");
    UIComponent panelGroup1 = root.findComponent("testGroup1");
    Assert.assertNotNull(panelGroup1);
    CompositeTestComponent compositeComponent1 = (CompositeTestComponent) panelGroup1.getChildren().get(0);
    Assert.assertNotNull(compositeComponent1);
    UIComponent facet1 = compositeComponent1.getFacet(UIComponent.COMPOSITE_FACET_NAME);
    Assert.assertNotNull(facet1);
    UIComponent compositeComponent2 = facet1.getChildren().get(0);
    Assert.assertNotNull(compositeComponent2);
    UIComponent facet2 = compositeComponent2.getFacet(UIComponent.COMPOSITE_FACET_NAME);
    Assert.assertNotNull(facet2);
    HtmlOutputText text1 = (HtmlOutputText) facet2.findComponent("text");
    Assert.assertNotNull(text1);
    HtmlCommandButton button1 = (HtmlCommandButton) facet2.findComponent("button");
    Assert.assertNotNull(button1);
    compositeComponent1.pushComponentToEL(facesContext, compositeComponent1);
    facet1.pushComponentToEL(facesContext, facet1);
    text1.pushComponentToEL(facesContext, text1);
    // set on tag
    Assert.assertEquals(bean.getStyleClass(), text1.getStyleClass());
    // set as default
    Assert.assertEquals(bean.getStyle(), text1.getStyle());
    Assert.assertEquals(bean.getJavaProperty(), text1.getValue());
    text1.popComponentFromEL(facesContext);
    button1.pushComponentToEL(facesContext, button1);
    MethodExpression method = button1.getActionExpression();
    Assert.assertEquals(bean.doSomethingFunny("xysj"), method.invoke(facesContext.getELContext(), new Object[] { "xysj" }));
    button1.popComponentFromEL(facesContext);
    facet1.popComponentFromEL(facesContext);
    compositeComponent1.popComponentFromEL(facesContext);
    StringWriter sw = new StringWriter();
    MockResponseWriter mrw = new MockResponseWriter(sw);
    facesContext.setResponseWriter(mrw);
    compositeComponent1.encodeAll(facesContext);
    sw.flush();
    HtmlRenderedAttr[] attrs = new HtmlRenderedAttr[] { new HtmlRenderedAttr("style") };
    HtmlCheckAttributesUtil.checkRenderedAttributes(attrs, sw.toString());
}
Also used : StringWriter(java.io.StringWriter) UIComponent(jakarta.faces.component.UIComponent) MockResponseWriter(org.apache.myfaces.test.mock.MockResponseWriter) HtmlCommandButton(jakarta.faces.component.html.HtmlCommandButton) HtmlOutputText(jakarta.faces.component.html.HtmlOutputText) HtmlRenderedAttr(org.apache.myfaces.test.utils.HtmlRenderedAttr) UIViewRoot(jakarta.faces.component.UIViewRoot) MethodExpression(jakarta.el.MethodExpression) Test(org.junit.Test)

Example 23 with HtmlOutputText

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

the class CompositeComponentAttributeTestCase method testSimpleCompositeAttribute.

/**
 * Test simple attribute resolution (not set, default, normal use case).
 *
 * @throws Exception
 */
@Test
public void testSimpleCompositeAttribute() throws Exception {
    MockAttributeBean bean = new MockAttributeBean();
    facesContext.getExternalContext().getRequestMap().put("bean", bean);
    UIViewRoot root = facesContext.getViewRoot();
    vdl.buildView(facesContext, root, "testSimpleAttributeVE.xhtml");
    UIComponent panelGroup1 = root.findComponent("testGroup1");
    Assert.assertNotNull(panelGroup1);
    CompositeTestComponent compositeComponent1 = (CompositeTestComponent) panelGroup1.getChildren().get(0);
    Assert.assertNotNull(compositeComponent1);
    UIComponent facet1 = compositeComponent1.getFacet(UIComponent.COMPOSITE_FACET_NAME);
    Assert.assertNotNull(facet1);
    HtmlOutputText text1 = (HtmlOutputText) facet1.findComponent("text");
    Assert.assertNotNull(text1);
    HtmlCommandButton button1 = (HtmlCommandButton) facet1.findComponent("button");
    Assert.assertNotNull(button1);
    HtmlInputText input1 = (HtmlInputText) facet1.findComponent("input");
    Assert.assertNotNull(input1);
    compositeComponent1.pushComponentToEL(facesContext, compositeComponent1);
    facet1.pushComponentToEL(facesContext, facet1);
    text1.pushComponentToEL(facesContext, text1);
    // set on tag
    Assert.assertEquals(bean.getStyleClass(), text1.getStyleClass());
    // set as default
    Assert.assertEquals(bean.getStyle(), text1.getStyle());
    Assert.assertEquals(bean.getJavaProperty(), text1.getValue());
    Assert.assertEquals(bean.getValue(), input1.getValue());
    Assert.assertEquals(true, input1.isRequired());
    text1.popComponentFromEL(facesContext);
    button1.pushComponentToEL(facesContext, button1);
    MethodExpression method = button1.getActionExpression();
    Assert.assertEquals(bean.doSomethingFunny("xysj"), method.invoke(facesContext.getELContext(), new Object[] { "xysj" }));
    button1.popComponentFromEL(facesContext);
    facet1.popComponentFromEL(facesContext);
    compositeComponent1.popComponentFromEL(facesContext);
    StringWriter sw = new StringWriter();
    MockResponseWriter mrw = new MockResponseWriter(sw);
    facesContext.setResponseWriter(mrw);
    compositeComponent1.encodeAll(facesContext);
    sw.flush();
    HtmlRenderedAttr[] attrs = new HtmlRenderedAttr[] { new HtmlRenderedAttr("style") };
    HtmlCheckAttributesUtil.checkRenderedAttributes(attrs, sw.toString());
}
Also used : UIComponent(jakarta.faces.component.UIComponent) HtmlInputText(jakarta.faces.component.html.HtmlInputText) HtmlCommandButton(jakarta.faces.component.html.HtmlCommandButton) MethodExpression(jakarta.el.MethodExpression) StringWriter(java.io.StringWriter) MockResponseWriter(org.apache.myfaces.test.mock.MockResponseWriter) HtmlOutputText(jakarta.faces.component.html.HtmlOutputText) HtmlRenderedAttr(org.apache.myfaces.test.utils.HtmlRenderedAttr) UIViewRoot(jakarta.faces.component.UIViewRoot) Test(org.junit.Test)

Example 24 with HtmlOutputText

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

the class UIRecursiveComponent method processEvent.

public void processEvent(SystemEvent event) throws AbortProcessingException {
    if (!FacesContext.getCurrentInstance().isPostback()) {
        HtmlOutputText component = new HtmlOutputText();
        component.setValue("Dynamically added child");
        getChildren().add(component);
        if (!(getParent() instanceof UIRecursiveComponent)) {
            getChildren().add(new UIRecursiveComponent());
        }
    }
}
Also used : HtmlOutputText(jakarta.faces.component.html.HtmlOutputText)

Example 25 with HtmlOutputText

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

the class UITableComponent method processEvent.

public void processEvent(SystemEvent event) throws AbortProcessingException {
    FacesContext context = FacesContext.getCurrentInstance();
    if (!context.isPostback()) {
        Application application = context.getApplication();
        HtmlDataTable dataTable = new HtmlDataTable();
        dataTable.setVar("_internal");
        dataTable.setValueExpression("value", application.getExpressionFactory().createValueExpression(context.getELContext(), "#{testManagedBean.list}", Object.class));
        getChildren().add(dataTable);
        UIColumn column = new UIColumn();
        column.setId(context.getViewRoot().createUniqueId());
        dataTable.getChildren().add(column);
        HtmlOutputText outputText = new HtmlOutputText();
        outputText.setId(context.getViewRoot().createUniqueId());
        outputText.setValueExpression("value", application.getExpressionFactory().createValueExpression(context.getELContext(), "#{_internal}", Object.class));
        column.getChildren().add(outputText);
    }
}
Also used : FacesContext(jakarta.faces.context.FacesContext) HtmlDataTable(jakarta.faces.component.html.HtmlDataTable) UIColumn(jakarta.faces.component.UIColumn) HtmlOutputText(jakarta.faces.component.html.HtmlOutputText) Application(jakarta.faces.application.Application)

Aggregations

HtmlOutputText (jakarta.faces.component.html.HtmlOutputText)31 UIViewRoot (jakarta.faces.component.UIViewRoot)11 Test (org.junit.Test)11 StringWriter (java.io.StringWriter)9 UIComponent (jakarta.faces.component.UIComponent)8 MockResponseWriter (org.apache.myfaces.test.mock.MockResponseWriter)8 UIColumn (jakarta.faces.component.UIColumn)7 UIOutput (jakarta.faces.component.UIOutput)7 HtmlDataTable (jakarta.faces.component.html.HtmlDataTable)7 HtmlColumn (jakarta.faces.component.html.HtmlColumn)6 HtmlInputText (jakarta.faces.component.html.HtmlInputText)6 ArrayList (java.util.ArrayList)5 UIData (jakarta.faces.component.UIData)4 HtmlCommandButton (jakarta.faces.component.html.HtmlCommandButton)4 ListDataModel (jakarta.faces.model.ListDataModel)4 ViewDeclarationLanguage (jakarta.faces.view.ViewDeclarationLanguage)4 Application (jakarta.faces.application.Application)3 FacesContext (jakarta.faces.context.FacesContext)3 HtmlRenderedAttr (org.apache.myfaces.test.utils.HtmlRenderedAttr)3 MethodExpression (jakarta.el.MethodExpression)2