Search in sources :

Example 1 with UIData

use of jakarta.faces.component.UIData 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 2 with UIData

use of jakarta.faces.component.UIData 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 UIData

use of jakarta.faces.component.UIData 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 UIData

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

the class UIDataTest method testCollectionDataModel.

public void testCollectionDataModel() throws Exception {
    SimpleCollection<RowData> model = new SimpleCollection<RowData>();
    model.add(new RowData("text1", "style1"));
    model.add(new RowData("text1", "style2"));
    model.add(new RowData("text1", "style3"));
    model.add(new RowData("text1", "style4"));
    // Put on request map to be resolved later
    request.setAttribute("list", model);
    UIViewRoot root = facesContext.getViewRoot();
    UIData table = new UIData();
    UIColumn column = new UIColumn();
    UIOutput text = new UIOutput();
    // This is only required if markInitiaState fix is not used
    root.setId(root.createUniqueId());
    table.setId(root.createUniqueId());
    column.setId(root.createUniqueId());
    text.setId(root.createUniqueId());
    table.setVar("row");
    table.setRowStatePreserved(true);
    table.setValueExpression("value", application.getExpressionFactory().createValueExpression(facesContext.getELContext(), "#{list}", Collection.class));
    text.setValueExpression("value", application.getExpressionFactory().createValueExpression(facesContext.getELContext(), "#{row.text}", String.class));
    root.getChildren().add(table);
    table.getChildren().add(column);
    column.getChildren().add(text);
    // Check the value expressions are working and change the component state
    int i = 0;
    for (Iterator<RowData> it = model.iterator(); it.hasNext(); ) {
        RowData rowData = it.next();
        table.setRowIndex(i);
        Assert.assertEquals(rowData.getText(), text.getValue());
        i++;
    }
    // Reset row index
    table.setRowIndex(-1);
}
Also used : UIColumn(jakarta.faces.component.UIColumn) UIOutput(jakarta.faces.component.UIOutput) AbstractCollection(java.util.AbstractCollection) Collection(java.util.Collection) UIViewRoot(jakarta.faces.component.UIViewRoot) VisitHint(jakarta.faces.component.visit.VisitHint) UIData(jakarta.faces.component.UIData)

Example 5 with UIData

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

the class UIDataTest method testProcessUpdatesRenderedFalse.

public void testProcessUpdatesRenderedFalse() throws Exception {
    UIData uiData = new VerifyNoLifecycleMethodComponent();
    UIComponent parent = MockRenderedValueExpression.setUpComponentStack(facesContext, uiData, false);
    uiData.processUpdates(facesContext);
    Assert.assertEquals("processUpdates must not change currentComponent", parent, UIComponent.getCurrentComponent(facesContext));
}
Also used : UIComponent(jakarta.faces.component.UIComponent) UIData(jakarta.faces.component.UIData)

Aggregations

UIData (jakarta.faces.component.UIData)54 PrintWriter (java.io.PrintWriter)23 UIColumn (jakarta.faces.component.UIColumn)18 UIViewRoot (jakarta.faces.component.UIViewRoot)17 UIComponent (jakarta.faces.component.UIComponent)13 UIOutput (jakarta.faces.component.UIOutput)11 ArrayList (java.util.ArrayList)10 FacesException (jakarta.faces.FacesException)9 ServletException (jakarta.servlet.ServletException)9 IOException (java.io.IOException)9 UIInput (jakarta.faces.component.UIInput)6 VisitHint (jakarta.faces.component.visit.VisitHint)6 ListDataModel (jakarta.faces.model.ListDataModel)6 Test (org.junit.Test)5 HtmlColumn (jakarta.faces.component.html.HtmlColumn)4 HtmlDataTable (jakarta.faces.component.html.HtmlDataTable)4 HtmlOutputText (jakarta.faces.component.html.HtmlOutputText)4 FacesContext (jakarta.faces.context.FacesContext)4 ResponseWriter (jakarta.faces.context.ResponseWriter)4 ContextCallback (jakarta.faces.component.ContextCallback)3