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