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