Search in sources :

Example 1 with DataTable

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);
        }
    }
}
Also used : DataTable(com.liferay.faces.alloy.component.datatable.DataTable) ResponseWriter(javax.faces.context.ResponseWriter) JavaScriptFragment(com.liferay.faces.util.render.JavaScriptFragment) EscapedClientId(com.liferay.faces.alloy.render.internal.EscapedClientId)

Example 2 with DataTable

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");
    }
}
Also used : DataTable(com.liferay.faces.alloy.component.datatable.DataTable) ResponseWriter(javax.faces.context.ResponseWriter)

Example 3 with DataTable

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);
}
Also used : DataTable(com.liferay.faces.alloy.component.datatable.DataTable) ExternalContext(javax.faces.context.ExternalContext)

Example 4 with DataTable

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);
}
Also used : DataTable(com.liferay.faces.alloy.component.datatable.DataTable)

Example 5 with DataTable

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");
    }
}
Also used : HtmlDataTable(javax.faces.component.html.HtmlDataTable) DataTable(com.liferay.faces.alloy.component.datatable.DataTable) Column(com.liferay.faces.alloy.component.column.Column) UIComponent(javax.faces.component.UIComponent)

Aggregations

DataTable (com.liferay.faces.alloy.component.datatable.DataTable)9 ResponseWriter (javax.faces.context.ResponseWriter)3 Column (com.liferay.faces.alloy.component.column.Column)1 EscapedClientId (com.liferay.faces.alloy.render.internal.EscapedClientId)1 Customer (com.liferay.faces.showcase.dto.Customer)1 JavaScriptFragment (com.liferay.faces.util.render.JavaScriptFragment)1 FacesMessage (javax.faces.application.FacesMessage)1 UICommand (javax.faces.component.UICommand)1 UIComponent (javax.faces.component.UIComponent)1 UISelectOne (javax.faces.component.UISelectOne)1 HtmlDataTable (javax.faces.component.html.HtmlDataTable)1 ExternalContext (javax.faces.context.ExternalContext)1 FacesContext (javax.faces.context.FacesContext)1