Skip to content

Commit

Permalink
add <caption> optional tag to datatable
Browse files Browse the repository at this point in the history
add <caption> optional tag to datatable to improve screen reader experience

Fix  #1028
  • Loading branch information
llebert authored and stephanrauh committed Nov 23, 2018
1 parent ea625a3 commit 3f3608b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -86,6 +86,22 @@ public boolean isBorder() {
public void setBorder(boolean _border) {
getStateHelper().put(PropertyKeys.border, _border);
}
/**
* If set, this will add a <caption> 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. <P>
* @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. <P>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3f3608b

Please sign in to comment.