diff --git a/src/main/java/net/bootsfaces/component/dataTable/DataTableCore.java b/src/main/java/net/bootsfaces/component/dataTable/DataTableCore.java index 8429f8f4f..7da24b5ad 100644 --- a/src/main/java/net/bootsfaces/component/dataTable/DataTableCore.java +++ b/src/main/java/net/bootsfaces/component/dataTable/DataTableCore.java @@ -24,7 +24,7 @@ public abstract class DataTableCore extends UIData implements net.bootsfaces.render.IHasTooltip { protected enum PropertyKeys { - ajax, autoUpdate, border, colLg, colMd, colSm, colXs, columnVisibility, contentDisabled, copy, csv, customLangUrl, customOptions, delay, deselectOnBackdropClick, disabled, display, excel, fixedHeader, hidden, immediate, info, lang, largeScreen, markSearchResults, mediumScreen, multiColumnSearch, multiColumnSearchPosition, offset, offsetLg, offsetMd, offsetSm, offsetXs, onclick, oncomplete, ondblclick, ondeselect, onerror, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, onorder, onpage, onsearch, onselect, onsuccess, pageLength, pageLengthMenu, paginated, pdf, print, process, responsive, rowGroup, rowHighlight, rowStyleClass, saveState, scrollCollapse, scrollHorizontally, scrollSize, scrollX, searching, select, selectedColumn, selectedItems, selectedRow, selectionInfo, selectionMode, smallScreen, span, striped, style, styleClass, tinyScreen, tooltip, tooltipContainer, tooltipDelay, tooltipDelayHide, tooltipDelayShow, tooltipPosition, update, visible, widgetVar; + ajax, autoUpdate, border, caption, colLg, colMd, colSm, colXs, columnVisibility, contentDisabled, copy, csv, customLangUrl, customOptions, delay, deselectOnBackdropClick, disabled, display, excel, fixedHeader, hidden, immediate, info, lang, largeScreen, markSearchResults, mediumScreen, multiColumnSearch, multiColumnSearchPosition, offset, offsetLg, offsetMd, offsetSm, offsetXs, onclick, oncomplete, ondblclick, ondeselect, onerror, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, onorder, onpage, onsearch, onselect, onsuccess, pageLength, pageLengthMenu, paginated, pdf, print, process, responsive, rowGroup, rowHighlight, rowStyleClass, saveState, scrollCollapse, scrollHorizontally, scrollSize, scrollX, searching, select, selectedColumn, selectedItems, selectedRow, selectionInfo, selectionMode, smallScreen, span, striped, style, styleClass, tinyScreen, tooltip, tooltipContainer, tooltipDelay, tooltipDelayHide, tooltipDelayShow, tooltipPosition, update, visible, widgetVar; String toString; PropertyKeys(String toString) { @@ -86,6 +86,22 @@ public boolean isBorder() { public void setBorder(boolean _border) { getStateHelper().put(PropertyKeys.border, _border); } + /** + * If set, this will add a tag in table declaration + */ + public void setcaption(String _caption) { + getStateHelper().put(PropertyKeys.caption, _caption); + } + + + /** + * If set, this will surround the table by a border. Defaults to true.

+ * @return Returns the value of the attribute, or "-1", if it hasn't been set by the JSF file. + */ + public String getCaption() { + return (String) getStateHelper().eval(PropertyKeys.caption, "-1"); + } + /** * Integer value to specify how many columns to span on large screens (≥1200 pixels wide). The number may optionally be followed by "column" or "columns". Alternative legal values: half, one-third, two-thirds, one-fourth, three-fourths.

diff --git a/src/main/java/net/bootsfaces/component/dataTable/DataTableRenderer.java b/src/main/java/net/bootsfaces/component/dataTable/DataTableRenderer.java index 5145a4284..77c798c40 100644 --- a/src/main/java/net/bootsfaces/component/dataTable/DataTableRenderer.java +++ b/src/main/java/net/bootsfaces/component/dataTable/DataTableRenderer.java @@ -134,6 +134,7 @@ public void encodeBegin(FacesContext context, UIComponent component) throws IOEx rw.writeAttribute("style", dataTable.getStyle(), "style"); AJAXRenderer.generateBootsFacesAJAXAndJavaScript(context, dataTable, rw, false); + generateCaption(context, dataTable, rw); generateHeader(context, dataTable, rw); generateBody(context, dataTable, rw); generateFooter(context, dataTable, rw); @@ -298,6 +299,20 @@ private void generateBody(FacesContext context, DataTable dataTable, ResponseWri rw.endElement("tbody"); dataTable.setRowIndex(-1); } + private void generateCaption(FacesContext context, DataTable dataTable, ResponseWriter rw) throws IOException { + boolean hasCaption = false; + + + if (!dataTable.getCaption().equals("-1")) { + hasCaption = true; + } + + if (hasCaption) { + rw.startElement("caption", dataTable); + rw.writeText(dataTable.getCaption(), null); + rw.endElement("caption"); + } + } private void renderChildrenOfColumn(UIComponent column, FacesContext context) throws IOException { resetClientIdCacheRecursively(column);