Search in sources :

Example 1 with Customer

use of com.liferay.faces.showcase.dto.Customer in project liferay-faces-alloy by liferay.

the class DataTableBacking method addFacesMessage.

protected void addFacesMessage(FacesEvent facesEvent, int[] rowIndexes, List<Object> customerList) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    StringBuilder messageText = new StringBuilder();
    messageText.append("Received ");
    messageText.append(facesEvent.getClass().getSimpleName());
    messageText.append(" for rowIndexes=");
    messageText.append(Arrays.toString(rowIndexes));
    if (customerList != null) {
        messageText.append(" Customers=[");
        for (int i = 0; i < customerList.size(); i++) {
            if (i > 0) {
                messageText.append(", ");
            }
            Customer customer = (Customer) customerList.get(i);
            messageText.append(customer.getFirstName());
            messageText.append(" ");
            messageText.append(customer.getLastName());
        }
        messageText.append("]");
    }
    messageText.append(" in the ");
    messageText.append(facesEvent.getPhaseId().toString());
    messageText.append(" phase.");
    FacesMessage facesMessage = new FacesMessage(messageText.toString());
    facesContext.addMessage(null, facesMessage);
}
Also used : FacesContext(javax.faces.context.FacesContext) Customer(com.liferay.faces.showcase.dto.Customer) FacesMessage(javax.faces.application.FacesMessage)

Example 2 with Customer

use of com.liferay.faces.showcase.dto.Customer 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)

Aggregations

Customer (com.liferay.faces.showcase.dto.Customer)2 FacesMessage (javax.faces.application.FacesMessage)2 FacesContext (javax.faces.context.FacesContext)2 DataTable (com.liferay.faces.alloy.component.datatable.DataTable)1 UICommand (javax.faces.component.UICommand)1