Search in sources :

Example 6 with DataTable

use of com.liferay.faces.alloy.component.datatable.DataTable in project liferay-faces-alloy by liferay.

the class DataTableBacking method modeSwitch.

public void modeSwitch(ValueChangeEvent valueChangeEvent) {
    UISelectOne selectOneMenu = (UISelectOne) valueChangeEvent.getSource();
    DataTable customerDataTable = (DataTable) selectOneMenu.findComponent("customers");
    customerDataTable.setSelectedRowIndexes(null);
}
Also used : DataTable(com.liferay.faces.alloy.component.datatable.DataTable) UISelectOne(javax.faces.component.UISelectOne)

Example 7 with DataTable

use of com.liferay.faces.alloy.component.datatable.DataTable in project liferay-faces-alloy by liferay.

the class DataTableBacking method determineSelectedCustomers.

public void determineSelectedCustomers(ActionEvent actionEvent) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    selectedCustomers = new ArrayList<Customer>();
    UICommand commandButton = (UICommand) actionEvent.getSource();
    DataTable customerDataTable = (DataTable) commandButton.findComponent("customers");
    String selectedRowIndexes = customerDataTable.getSelectedRowIndexes();
    if ((selectedRowIndexes != null) && (selectedRowIndexes.length() > 0)) {
        int originalRowIndex = customerDataTable.getRowIndex();
        String[] selectedRowIndexArray = selectedRowIndexes.split(",");
        StringBuilder facesMessageText = new StringBuilder();
        for (String selectedRowIndex : selectedRowIndexArray) {
            int rowIndex = Integer.parseInt(selectedRowIndex);
            customerDataTable.setRowIndex(rowIndex);
            Customer customer = (Customer) customerDataTable.getRowData();
            selectedCustomers.add(customer);
            if (facesMessageText.length() > 0) {
                facesMessageText.append(", ");
            }
            facesMessageText.append(customer.getFirstName());
            facesMessageText.append(" ");
            facesMessageText.append(customer.getLastName());
        }
        if (facesMessageText.length() > 0) {
            FacesMessage facesMessage = new FacesMessage(facesMessageText.toString());
            facesContext.addMessage(null, facesMessage);
        }
        customerDataTable.setRowIndex(originalRowIndex);
    } else {
        FacesMessage facesMessage = new FacesMessage("No Customers Selected");
        facesContext.addMessage(null, facesMessage);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) DataTable(com.liferay.faces.alloy.component.datatable.DataTable) Customer(com.liferay.faces.showcase.dto.Customer) UICommand(javax.faces.component.UICommand) FacesMessage(javax.faces.application.FacesMessage)

Example 8 with DataTable

use of com.liferay.faces.alloy.component.datatable.DataTable in project liferay-faces-alloy by liferay.

the class DataTableRenderer method encodeMarkupBegin.

@Override
public void encodeMarkupBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    // If the rows attribute has changed since the last render, then reset the first row that is to be displayed
    // back to zero. This takes care of any page number rendering difficulties.
    DataTable dataTable = (DataTable) uiComponent;
    Map<String, Object> dataTableAttributes = dataTable.getAttributes();
    Integer oldRows = (Integer) dataTableAttributes.remove("oldRows");
    if ((oldRows != null) && (oldRows != dataTable.getRows())) {
        dataTable.setFirst(0);
    }
    // Encode the starting <table> element that represents the alloy:table.
    DataTableInfo dataTableInfo = new DataTableInfo(dataTable);
    ResponseWriter responseWriter = facesContext.getResponseWriter();
    responseWriter.startElement("table", dataTable);
    responseWriter.writeAttribute("id", dataTable.getClientId(facesContext), "id");
    RendererUtil.encodeStyleable(responseWriter, dataTable);
    // If present, encode the child <f:facet name="caption" ... />
    encodeCaptionFacet(facesContext, responseWriter, dataTable);
    // If present, encode the child <f:facet name="colGroups" ... />
    encodeColGroupsFacet(facesContext, dataTable);
    // Encode the table <thead> ... </thead> section.
    encodeHeader(facesContext, responseWriter, dataTable, dataTableInfo);
    // Encode the table <tfoot> ... </tfoot> section.
    encodeFooter(facesContext, responseWriter, dataTable, dataTableInfo);
}
Also used : DataTable(com.liferay.faces.alloy.component.datatable.DataTable) ResponseWriter(javax.faces.context.ResponseWriter)

Example 9 with DataTable

use of com.liferay.faces.alloy.component.datatable.DataTable in project liferay-faces-alloy by liferay.

the class DataTableRenderer method encodeClientState.

@Override
public void encodeClientState(FacesContext facesContext, ResponseWriter responseWriter, UIComponent uiComponent) throws IOException {
    // Set the rowIndex to -1 so that the UIData.getClientId(FacesContext) method will return a clientId that does
    // not append the rowIndex. This is necessary to ensure that state saving/restoring will take place correctly,
    // since the state is referenced by the clientId.
    DataTable dataTable = (DataTable) uiComponent;
    dataTable.setRowIndex(-1);
    // Encode the hidden field that contains the client-side state of the selected index.
    String hiddenFieldName = dataTable.getClientId(facesContext).concat("_selectedRowIndexes");
    responseWriter.startElement("input", dataTable);
    responseWriter.writeAttribute("id", hiddenFieldName, null);
    responseWriter.writeAttribute("name", hiddenFieldName, null);
    responseWriter.writeAttribute("type", "hidden", null);
    responseWriter.writeAttribute("value", dataTable.getSelectedRowIndexes(), null);
    responseWriter.endElement("input");
}
Also used : DataTable(com.liferay.faces.alloy.component.datatable.DataTable)

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