Search in sources :

Example 26 with HtmlOutputText

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

the class HtmlGridRendererTest method setUp.

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

Example 27 with HtmlOutputText

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

the class HtmlGridRendererTest method testRenderTable.

public void testRenderTable() throws Exception {
    UIColumn col1 = new UIColumn();
    HtmlOutputText col1Text = new HtmlOutputText();
    col1Text.setValue("col1Text");
    UIColumn col2 = new UIColumn();
    HtmlOutputText col2Text = new HtmlOutputText();
    col2Text.setValue("col2Text");
    col1.getChildren().add(col1Text);
    col2.getChildren().add(col2Text);
    panelGrid.getChildren().add(col1);
    panelGrid.getChildren().add(col2);
    panelGrid.encodeBegin(facesContext);
    panelGrid.encodeChildren(facesContext);
    panelGrid.encodeEnd(facesContext);
    facesContext.renderResponse();
    String output = writer.getWriter().toString();
    Assert.assertEquals("<table><tbody>" + "<tr><td>col1Text</td></tr>" + "<tr><td>col2Text</td></tr>" + "</tbody>" + "</table>", output);
}
Also used : UIColumn(jakarta.faces.component.UIColumn) HtmlOutputText(jakarta.faces.component.html.HtmlOutputText)

Example 28 with HtmlOutputText

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

the class UIDataRowStateTest method testChangeIdsAfterSetRowIndex.

/**
 */
@Test
public void testChangeIdsAfterSetRowIndex() {
    List<Item> list = new ArrayList<Item>();
    int rowCount = 10;
    for (int i = 0; i < rowCount; i++) {
        list.add(new Item(i, "name" + i, "lastName" + i));
    }
    facesContext.getExternalContext().getRequestMap().put("items", list);
    UIViewRoot root = facesContext.getViewRoot();
    UIData data = new HtmlDataTable();
    data.setId("table");
    root.getChildren().add(data);
    data.setValue(new ListDataModel(list));
    data.setVar("item");
    data.setRows(rowCount);
    UIColumn col = new HtmlColumn();
    data.getChildren().add(col);
    UIOutput text = new HtmlOutputText();
    text.setId("text");
    text.setValue(facesContext.getApplication().getExpressionFactory().createValueExpression(facesContext.getELContext(), "#{item.name}", String.class));
    col.getChildren().add(text);
    for (int i = 0; i < rowCount; i++) {
        data.setRowIndex(i);
        Assert.assertEquals(data.getId() + ":" + i + ":" + text.getId(), text.getClientId());
    }
    data.setRowIndex(-1);
    Assert.assertEquals(data.getId() + ":" + text.getId(), text.getClientId());
}
Also used : HtmlDataTable(jakarta.faces.component.html.HtmlDataTable) UIColumn(jakarta.faces.component.UIColumn) ArrayList(java.util.ArrayList) ListDataModel(jakarta.faces.model.ListDataModel) UIData(jakarta.faces.component.UIData) HtmlColumn(jakarta.faces.component.html.HtmlColumn) UIOutput(jakarta.faces.component.UIOutput) HtmlOutputText(jakarta.faces.component.html.HtmlOutputText) UIViewRoot(jakarta.faces.component.UIViewRoot) Test(org.junit.Test)

Example 29 with HtmlOutputText

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

the class UIDataRowStateTest method setUpRenderKit.

@Override
protected void setUpRenderKit() throws Exception {
    super.setUpRenderKit();
    renderKit.addRenderer(HtmlDataTable.COMPONENT_FAMILY, new HtmlDataTable().getRendererType(), new Renderer() {
    });
    renderKit.addRenderer(HtmlOutputText.COMPONENT_FAMILY, new HtmlOutputText().getRendererType(), new Renderer() {
    });
    renderKit.addRenderer(HtmlInputText.COMPONENT_FAMILY, new HtmlInputText().getRendererType(), new Renderer() {
    });
}
Also used : HtmlDataTable(jakarta.faces.component.html.HtmlDataTable) Renderer(jakarta.faces.render.Renderer) HtmlInputText(jakarta.faces.component.html.HtmlInputText) HtmlOutputText(jakarta.faces.component.html.HtmlOutputText)

Example 30 with HtmlOutputText

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

the class UIDataRowStateTest method testEditableValueHolderState.

/**
 * Check if EditableValueHolder is being saved and restored.
 */
@Test
public void testEditableValueHolderState() {
    List<Item> list = new ArrayList<Item>();
    int rowCount = 10;
    for (int i = 0; i < rowCount; i++) {
        list.add(new Item(i, "name" + i, "lastName" + i));
    }
    facesContext.getExternalContext().getRequestMap().put("items", list);
    UIViewRoot root = facesContext.getViewRoot();
    UIData data = new HtmlDataTable();
    data.setId("table");
    root.getChildren().add(data);
    data.setValue(new ListDataModel(list));
    data.setVar("item");
    data.setRows(rowCount);
    UIColumn col = new HtmlColumn();
    data.getChildren().add(col);
    UIOutput text = new HtmlOutputText();
    text.setId("text");
    text.setValue(facesContext.getApplication().getExpressionFactory().createValueExpression(facesContext.getELContext(), "#{item.name}", String.class));
    col.getChildren().add(text);
    UIInput inputText = new HtmlInputText();
    inputText.setId("text");
    inputText.setValue(facesContext.getApplication().getExpressionFactory().createValueExpression(facesContext.getELContext(), "#{item.lastName}", String.class));
    col.getChildren().add(inputText);
    for (int i = 0; i < rowCount; i++) {
        data.setRowIndex(i);
        inputText.setSubmittedValue("someString" + i);
    }
    data.setRowIndex(-1);
    for (int i = 0; i < rowCount; i++) {
        data.setRowIndex(i);
        Assert.assertEquals("someString" + i, inputText.getSubmittedValue());
    }
}
Also used : HtmlDataTable(jakarta.faces.component.html.HtmlDataTable) UIColumn(jakarta.faces.component.UIColumn) ArrayList(java.util.ArrayList) HtmlInputText(jakarta.faces.component.html.HtmlInputText) UIInput(jakarta.faces.component.UIInput) ListDataModel(jakarta.faces.model.ListDataModel) UIData(jakarta.faces.component.UIData) HtmlColumn(jakarta.faces.component.html.HtmlColumn) UIOutput(jakarta.faces.component.UIOutput) HtmlOutputText(jakarta.faces.component.html.HtmlOutputText) UIViewRoot(jakarta.faces.component.UIViewRoot) Test(org.junit.Test)

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