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