use of jakarta.faces.model.ListDataModel 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.model.ListDataModel 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.model.ListDataModel in project myfaces by apache.
the class InvokeOnComponentTest method testInvokeOnCompOnUIDataChildren.
public void testInvokeOnCompOnUIDataChildren() throws Exception {
// column1
UIColumn c1 = new UIColumn();
c1.setId("col1");
UIOutput headerFacet = new UIOutput();
headerFacet.setValue("HEADER");
headerFacet.setId("header");
c1.setHeader(headerFacet);
UIOutput name = new UIOutput();
name.setValue("#{data.username}");
c1.getChildren().add(name);
// column2
UIColumn c2 = new UIColumn();
c2.setId("col2");
UIOutput secondheaderFacet = new UIOutput();
secondheaderFacet.setValue("New HEADER");
secondheaderFacet.setId("header2");
c2.setHeader(secondheaderFacet);
UIOutput passwd = new UIOutput();
passwd.setValue("#{data.password}");
c2.getChildren().add(passwd);
// main table
UIData table = new UIData();
table.setId("table");
table.setVar("data");
table.getChildren().add(c1);
table.getChildren().add(c2);
DataModel model = new ListDataModel(createTestData());
table.setValue(model);
this.facesContext.getViewRoot().getChildren().add(table);
System.out.println("RC; " + table.getRowCount());
table.encodeBegin(facesContext);
System.out.println("RC; " + table.getRowCount());
this.facesContext.getViewRoot().invokeOnComponent(facesContext, passwd.getClientId(facesContext), cc);
Mockito.verify(cc, Mockito.never()).invokeContextCallback(facesContext, table);
Mockito.verify(cc, Mockito.never()).invokeContextCallback(facesContext, passwd);
Mockito.verify(cc, Mockito.never()).invokeContextCallback(facesContext, c1);
Mockito.verify(cc, Mockito.never()).invokeContextCallback(facesContext, name);
}
use of jakarta.faces.model.ListDataModel in project mojarra by eclipse-ee4j.
the class UIRepeat method getDataModel.
private DataModel getDataModel() {
if (model == null) {
Object val = getValue();
if (val == null) {
Integer begin = getBegin();
Integer end = getEnd();
if (end == null) {
if (begin == null) {
model = EMPTY_MODEL;
} else {
throw new IllegalArgumentException("end");
}
} else {
int b = begin == null ? 0 : begin;
int e = end;
int d = b < e ? 1 : b > e ? -1 : 0;
int s = Math.abs(e - b) + 1;
Integer[] array = new Integer[s];
for (int i = 0; i < s; i++) {
array[i] = b + i * d;
}
model = new ArrayDataModel<>(array);
setBegin(0);
setEnd(s);
}
} else if (val instanceof DataModel) {
// noinspection unchecked
model = (DataModel<Object>) val;
} else if (val instanceof List) {
// noinspection unchecked
model = new ListDataModel<>((List<Object>) val);
} else if (Object[].class.isAssignableFrom(val.getClass())) {
model = new ArrayDataModel<>((Object[]) val);
} else if (val instanceof ResultSet) {
model = new ResultSetDataModel((ResultSet) val);
} else if (val instanceof Iterable) {
model = new IterableDataModel<>((Iterable<?>) val);
} else if (val instanceof Map) {
model = new IterableDataModel<>(((Map<?, ?>) val).entrySet());
} else {
DataModel<?> dataModel = createDataModel(val.getClass());
if (dataModel != null) {
dataModel.setWrappedData(val);
model = dataModel;
} else {
model = new ScalarDataModel<>(val);
}
}
}
return model;
}
use of jakarta.faces.model.ListDataModel in project myfaces by apache.
the class UIDataRowStateTest method testChangeIdsAfterSetRowIndex.
/**
*/
@Test
public void testChangeIdsAfterSetRowIndex() {
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);
for (int i = 0; i < rowCount; i++) {
data.setRowIndex(i);
Assert.assertEquals(data.getId() + ":" + i + ":" + text.getId(), text.getClientId());
}
data.setRowIndex(-1);
Assert.assertEquals(data.getId() + ":" + text.getId(), text.getClientId());
}
Aggregations