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);
}
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);
}
}
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);
}
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");
}
Aggregations