Search in sources :

Example 1 with UIColumn

use of jakarta.faces.component.UIColumn in project myfaces by apache.

the class HtmlTableRendererTest method testNoRowCountRender.

/**
 * Check table renderer behavior when DataModel returns -1 from getRowCount(). It should
 * render the same as if that value is provided. Note t:dataTable newspaper mode requires
 * row count to calculate newspaperRows and newspaperColumns.
 */
public void testNoRowCountRender() {
    List<Person> list = new ArrayList<Person>();
    list.add(new Person("John", "Smith"));
    list.add(new Person("Pepito", "Perez"));
    list.add(new Person("Kurt", "Kobain"));
    dataTable.setId("data");
    dataTable.setRowClasses("class1, class2");
    dataTable.setVar("person");
    UIColumn column1 = new UIColumn();
    HtmlOutputText text = new HtmlOutputText();
    text.setValueExpression("value", facesContext.getApplication().getExpressionFactory().createValueExpression(facesContext.getELContext(), "#{person.firstName}", String.class));
    column1.getChildren().add(text);
    dataTable.getChildren().add(column1);
    UIColumn column2 = new UIColumn();
    HtmlOutputText text2 = new HtmlOutputText();
    text2.setValueExpression("value", facesContext.getApplication().getExpressionFactory().createValueExpression(facesContext.getELContext(), "#{person.lastName}", String.class));
    column2.getChildren().add(text2);
    dataTable.getChildren().add(column2);
    dataTable.setValue(new UnknownRowCountDemoDataModel<Person>(list));
    String output1 = null;
    try {
        dataTable.encodeAll(facesContext);
        output1 = ((StringWriter) writer.getWriter()).getBuffer().toString();
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
    dataTable.setValue(new ListDataModel<Person>(list));
    ((StringWriter) writer.getWriter()).getBuffer().setLength(0);
    String output2 = null;
    try {
        dataTable.encodeAll(facesContext);
        output2 = ((StringWriter) writer.getWriter()).getBuffer().toString();
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
    Assert.assertTrue(output2.contains("John"));
    Assert.assertTrue(output2.contains("Smith"));
    Assert.assertTrue(output2.contains("class1"));
    Assert.assertTrue(output2.contains("class2"));
    Assert.assertTrue(output1.contains("John"));
    Assert.assertTrue(output1.contains("Smith"));
    Assert.assertTrue(output1.contains("class1"));
    Assert.assertTrue(output1.contains("class2"));
    Assert.assertEquals(output2, output1);
}
Also used : UIColumn(jakarta.faces.component.UIColumn) StringWriter(java.io.StringWriter) ArrayList(java.util.ArrayList) HtmlOutputText(jakarta.faces.component.html.HtmlOutputText)

Example 2 with UIColumn

use of jakarta.faces.component.UIColumn in project myfaces by apache.

the class UIComponentFindComponentTest method testXXFindComponent.

public void testXXFindComponent() {
    UIViewRoot viewRoot = new UIViewRoot();
    UIData uiData = new UIData();
    uiData.setId("x");
    UIColumn column = new UIColumn();
    column.setId("column");
    UICommand command = new UICommand();
    command.setId("x");
    viewRoot.getChildren().add(uiData);
    uiData.getChildren().add(column);
    column.getChildren().add(command);
    Assert.assertNull(viewRoot.findComponent(":xx"));
    Assert.assertNotNull(viewRoot.findComponent(":x"));
    Assert.assertNotNull(viewRoot.findComponent(":x:column"));
    Assert.assertNotNull(viewRoot.findComponent(":x:x"));
}
Also used : UIColumn(jakarta.faces.component.UIColumn) UICommand(jakarta.faces.component.UICommand) UIViewRoot(jakarta.faces.component.UIViewRoot) UIData(jakarta.faces.component.UIData)

Example 3 with UIColumn

use of jakarta.faces.component.UIColumn in project myfaces by apache.

the class UIDataRowStateTest method testAddRowAfterSetRowIndex.

@Test
public void testAddRowAfterSetRowIndex() {
    List<Item> list = new ArrayList<Item>();
    int rowCount = 10;
    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);
    data.setRowIndex(-1);
    data.processDecodes(facesContext);
    for (int i = 0; i < rowCount; i++) {
        list.add(new Item(i, "name" + i, "lastName" + i));
    }
    data.processDecodes(facesContext);
}
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 4 with UIColumn

use of jakarta.faces.component.UIColumn in project myfaces by apache.

the class UIDataRowStateTest method testChangeIdsAfterSetRowIndex2.

@Test
public void testChangeIdsAfterSetRowIndex2() {
    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);
        Assert.assertEquals(data.getId() + ":" + i + ":" + text.getId(), text.getClientId());
        Assert.assertEquals(data.getId() + ":" + i + ":" + inputText.getId(), inputText.getClientId());
    }
    data.setRowIndex(-1);
    Assert.assertEquals(data.getId() + ":" + text.getId(), text.getClientId());
    Assert.assertEquals(data.getId() + ":" + inputText.getId(), inputText.getClientId());
}
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)

Example 5 with UIColumn

use of jakarta.faces.component.UIColumn in project myfaces by apache.

the class UIDataTest method _addColumn.

private void _addColumn() {
    UIColumn uiColumn = new UIColumn();
    uiColumn.setId("testId");
    _testImpl.getChildren().add(uiColumn);
    MockRenderedValueExpression ve = new MockRenderedValueExpression("#{component.is eq 'testId'}", Boolean.class, uiColumn, true);
    uiColumn.setValueExpression("rendered", ve);
}
Also used : UIColumn(jakarta.faces.component.UIColumn) MockRenderedValueExpression(org.apache.myfaces.test.mock.MockRenderedValueExpression)

Aggregations

UIColumn (jakarta.faces.component.UIColumn)33 UIData (jakarta.faces.component.UIData)18 UIOutput (jakarta.faces.component.UIOutput)13 UIViewRoot (jakarta.faces.component.UIViewRoot)11 ArrayList (java.util.ArrayList)11 UIComponent (jakarta.faces.component.UIComponent)9 UIInput (jakarta.faces.component.UIInput)7 HtmlOutputText (jakarta.faces.component.html.HtmlOutputText)7 VisitHint (jakarta.faces.component.visit.VisitHint)6 ListDataModel (jakarta.faces.model.ListDataModel)6 HtmlDataTable (jakarta.faces.component.html.HtmlDataTable)5 HtmlColumn (jakarta.faces.component.html.HtmlColumn)4 FacesContext (jakarta.faces.context.FacesContext)4 Test (org.junit.Test)4 UICommand (jakarta.faces.component.UICommand)3 DataModel (jakarta.faces.model.DataModel)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ObjectInputStream (java.io.ObjectInputStream)3 ObjectOutputStream (java.io.ObjectOutputStream)3