Search in sources :

Example 1 with HtmlDataTable

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

the class HtmlTableRendererTest method setUp.

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

Example 2 with HtmlDataTable

use of jakarta.faces.component.html.HtmlDataTable 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 3 with HtmlDataTable

use of jakarta.faces.component.html.HtmlDataTable 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 4 with HtmlDataTable

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

the class AcidMyFacesRequestTestCase method testTable.

@Test
public void testTable() throws Exception {
    startViewRequest("/table.xhtml");
    processLifecycleExecuteAndRender();
    UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
    Assert.assertEquals(1, comp.getChildCount());
    HtmlDataTable dataTable = (HtmlDataTable) comp.getChildren().get(0);
    Assert.assertEquals(1, dataTable.getChildCount());
    UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
    client.submit(button);
    processLifecycleExecuteAndRender();
    comp = facesContext.getViewRoot().findComponent("mainForm:component");
    Assert.assertEquals(1, comp.getChildCount());
    dataTable = (HtmlDataTable) comp.getChildren().get(0);
    Assert.assertEquals(1, dataTable.getChildCount());
}
Also used : HtmlDataTable(jakarta.faces.component.html.HtmlDataTable) UIComponent(jakarta.faces.component.UIComponent) UICommand(jakarta.faces.component.UICommand) Test(org.junit.Test)

Example 5 with HtmlDataTable

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

the class HtmlRendererUtils method renderTableCaption.

public static void renderTableCaption(FacesContext context, ResponseWriter writer, UIComponent component) throws IOException {
    UIComponent captionFacet = component.getFacet("caption");
    if (captionFacet == null) {
        return;
    }
    String captionClass;
    String captionStyle;
    if (component instanceof HtmlPanelGrid) {
        HtmlPanelGrid panelGrid = (HtmlPanelGrid) component;
        captionClass = panelGrid.getCaptionClass();
        captionStyle = panelGrid.getCaptionStyle();
    } else if (component instanceof HtmlDataTable) {
        HtmlDataTable dataTable = (HtmlDataTable) component;
        captionClass = dataTable.getCaptionClass();
        captionStyle = dataTable.getCaptionStyle();
    } else {
        captionClass = (String) component.getAttributes().get(ComponentAttrs.CAPTION_CLASS_ATTR);
        captionStyle = (String) component.getAttributes().get(ComponentAttrs.CAPTION_STYLE_ATTR);
    }
    // component);
    writer.startElement(HTML.CAPTION_ELEM, null);
    if (captionClass != null) {
        writer.writeAttribute(HTML.CLASS_ATTR, captionClass, null);
    }
    if (captionStyle != null) {
        writer.writeAttribute(HTML.STYLE_ATTR, captionStyle, null);
    }
    // RendererUtils.renderChild(context, captionFacet);
    captionFacet.encodeAll(context);
    writer.endElement(HTML.CAPTION_ELEM);
}
Also used : HtmlDataTable(jakarta.faces.component.html.HtmlDataTable) UIComponent(jakarta.faces.component.UIComponent) HtmlPanelGrid(jakarta.faces.component.html.HtmlPanelGrid)

Aggregations

HtmlDataTable (jakarta.faces.component.html.HtmlDataTable)9 HtmlOutputText (jakarta.faces.component.html.HtmlOutputText)7 UIColumn (jakarta.faces.component.UIColumn)5 Test (org.junit.Test)5 UIData (jakarta.faces.component.UIData)4 UIOutput (jakarta.faces.component.UIOutput)4 UIViewRoot (jakarta.faces.component.UIViewRoot)4 HtmlColumn (jakarta.faces.component.html.HtmlColumn)4 ListDataModel (jakarta.faces.model.ListDataModel)4 ArrayList (java.util.ArrayList)4 HtmlInputText (jakarta.faces.component.html.HtmlInputText)3 UIComponent (jakarta.faces.component.UIComponent)2 UIInput (jakarta.faces.component.UIInput)2 Application (jakarta.faces.application.Application)1 UICommand (jakarta.faces.component.UICommand)1 HtmlPanelGrid (jakarta.faces.component.html.HtmlPanelGrid)1 FacesContext (jakarta.faces.context.FacesContext)1 Renderer (jakarta.faces.render.Renderer)1 StringWriter (java.io.StringWriter)1 MockResponseWriter (org.apache.myfaces.test.mock.MockResponseWriter)1