use of com.liferay.faces.alloy.component.datatable.DataTable in project liferay-faces-alloy by liferay.
the class DataTableRenderer method encodeJavaScriptCustom.
@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
DataTable dataTable = (DataTable) uiComponent;
String selectionMode = dataTable.getSelectionMode();
if ("checkbox".equals(selectionMode) || "radio".equals(selectionMode)) {
String dataTableClientId = dataTable.getClientId(facesContext);
EscapedClientId escapedDataTableClientId = new EscapedClientId(dataTableClientId);
String hiddenFieldClientId = dataTableClientId.concat("_selectedRowIndexes");
EscapedClientId escapedHiddenFieldClientId = new EscapedClientId(hiddenFieldClientId);
ResponseWriter responseWriter = facesContext.getResponseWriter();
// rowSelect
JavaScriptFragment rowSelectClientBehaviorScript = getRowEventClientBehaviorScript(facesContext, dataTable, dataTableClientId, RowSelectEvent.ROW_SELECT, "rowIndex");
// rowSelectRange
JavaScriptFragment rowSelectRangeClientBehaviorScript = getRowEventClientBehaviorScript(facesContext, dataTable, dataTableClientId, RowSelectRangeEvent.ROW_SELECT_RANGE, "rowIndexRange");
// rowDeselect
JavaScriptFragment rowDeselectClientBehaviorScript = getRowEventClientBehaviorScript(facesContext, dataTable, dataTableClientId, RowDeselectEvent.ROW_DESELECT, "rowIndex");
// rowDeSelectRange
JavaScriptFragment rowDeselectRangeClientBehaviorScript = getRowEventClientBehaviorScript(facesContext, dataTable, dataTableClientId, RowDeselectRangeEvent.ROW_DESELECT_RANGE, "rowIndexRange");
if ("checkbox".equals(selectionMode)) {
// Register the onclick event callback for the "Select All" checkbox.
String selectAllCheckboxClientId = dataTableClientId.concat("_selectAll");
EscapedClientId escapedSelectAllCheckboxClientId = new EscapedClientId(selectAllCheckboxClientId);
encodeFunctionCall(responseWriter, "LFAI.initDataTableSelectAllCheckbox", 'A', escapedDataTableClientId, escapedSelectAllCheckboxClientId, rowSelectRangeClientBehaviorScript, rowDeselectRangeClientBehaviorScript);
// Register the onclick event callback for each row-level checkbox.
encodeFunctionCall(responseWriter, "LFAI.initDataTableCheckboxSelection", 'A', escapedDataTableClientId, escapedHiddenFieldClientId, rowSelectClientBehaviorScript, rowDeselectClientBehaviorScript);
} else if ("radio".equals(selectionMode)) {
// Register the onclick event callback for each row-level radio button.
encodeFunctionCall(responseWriter, "LFAI.initDataTableRadioSelection", 'A', escapedDataTableClientId, escapedHiddenFieldClientId, rowSelectClientBehaviorScript, rowDeselectClientBehaviorScript);
}
}
}
use of com.liferay.faces.alloy.component.datatable.DataTable in project liferay-faces-alloy by liferay.
the class DataTableRenderer method encodeChildren.
@Override
public void encodeChildren(FacesContext facesContext, UIComponent uiComponent) throws IOException {
DataTable dataTable = (DataTable) uiComponent;
DataTableInfo dataTableInfo = new DataTableInfo(dataTable);
ResponseWriter responseWriter = facesContext.getResponseWriter();
int totalRenderedColumns = dataTableInfo.getTotalRenderedColumns();
if (totalRenderedColumns == 0) {
responseWriter.startElement("tbody", dataTable);
responseWriter.endElement("tbody");
} else {
int rows = dataTable.getRows();
int rowIndex = dataTable.getFirst() - 1;
int totalRowsEncoded = 0;
int[] bodyRows = dataTable.toIntArray(dataTable.getBodyrows());
boolean wroteTBody = false;
if (bodyRows == null) {
responseWriter.startElement("tbody", dataTable);
wroteTBody = true;
}
if (rows >= 0) {
ItemCycler rowClasses = new ItemCycler(dataTable.getRowClasses());
ItemCycler columnClasses = new ItemCycler(dataTable.getColumnClasses());
while ((totalRowsEncoded < rows) || (rows == 0)) {
rowIndex++;
dataTable.setRowIndex(rowIndex);
columnClasses.reset();
// If there is data in the model for the current row index, then encode the row.
if (dataTable.isRowAvailable()) {
if (bodyRows != null) {
for (int bodyRow : bodyRows) {
if (bodyRow == rowIndex) {
if (wroteTBody) {
responseWriter.endElement("tbody");
}
responseWriter.startElement("tbody", dataTable);
wroteTBody = true;
break;
}
}
}
encodeRow(facesContext, responseWriter, dataTable, rowIndex, rowClasses, columnClasses);
totalRowsEncoded++;
} else // Otherwise, encoding of rows is complete since the last row has been encoded.
{
break;
}
}
}
if (totalRowsEncoded == 0) {
String selectionMode = dataTable.getSelectionMode();
if ("checkbox".equals(selectionMode)) {
totalRenderedColumns += 1;
}
encodeEmptyTableRow(responseWriter, dataTable, totalRenderedColumns);
}
responseWriter.endElement("tbody");
}
}
use of com.liferay.faces.alloy.component.datatable.DataTable in project liferay-faces-alloy by liferay.
the class DataTableRenderer method decodeClientState.
@Override
public void decodeClientState(FacesContext facesContext, UIComponent uiComponent) {
// Apply the client-side state of the selected index.
ExternalContext externalContext = facesContext.getExternalContext();
Map<String, String> requestParameterMap = externalContext.getRequestParameterMap();
DataTable dataTable = (DataTable) uiComponent;
String dataTableClientId = dataTable.getClientId(facesContext);
decodeSortCriteria(facesContext, requestParameterMap, dataTable, dataTableClientId);
decodeRowSelection(requestParameterMap, dataTable, dataTableClientId);
}
use of com.liferay.faces.alloy.component.datatable.DataTable in project liferay-faces-alloy by liferay.
the class DataTableRendererBase method encodeAlloyAttributes.
@Override
public void encodeAlloyAttributes(FacesContext facesContext, ResponseWriter responseWriter, UIComponent uiComponent) throws IOException {
DataTable dataTable = (DataTable) uiComponent;
boolean first = true;
encodeHiddenAttributes(facesContext, responseWriter, dataTable, first);
}
use of com.liferay.faces.alloy.component.datatable.DataTable in project liferay-faces-alloy by liferay.
the class ColumnRenderer method processEvent.
@Override
public void processEvent(ComponentSystemEvent componentSystemEvent) throws AbortProcessingException {
Column column = (Column) componentSystemEvent.getComponent();
UIComponent parent = column.getParent();
if ((parent instanceof DataTable) && column.isAjax()) {
RendererUtil.addDefaultAjaxBehavior(column, column.getExecute(), column.getProcess(), "@parent", column.getRender(), column.getUpdate(), "@parent");
}
}
Aggregations