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