I modifed the DataExporter demo code so that it populates the DataTable when a "Submit" commandButton is clicked. The data is not exported, only the headers.
Could anyone tell me if I am not updating the correct ui component or if it is a bug?
The submit button code:
Code: Select all
<p:commandButton value="Submit" process="@form"
actionListener="#{tableBean.submit}"
update="testFormId,tbl" />
xhtml:
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<f:view content-type="text/html">
<h:head>
<f:facet name="first">
<meta http-equiv="X-UA-Compatible" content="EmulateIE8" />
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type" />
<title>Forecast</title>
</f:facet>
<style type="text/css">
.ui-layout-north {
z-index: 20 !important;
overflow: visible !important;;
}
.ui-layout-north .ui-layout-unit-content {
overflow: visible !important;
}
.ui-widget,.ui-widget .ui-widget {
font-size: 90% !important;
}
.label {
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: normal;
}
</style>
<!--
<h:outputStylesheet>
.ui-widget, .ui-widget .ui-widget {
font-size: 50% !important;
}
</h:outputStylesheet>
-->
</h:head>
<h:body>
<p:layout fullPage="true">
<p:layoutUnit position="north" size="100" header="" resizable="true"
closable="false" collapsible="true">
</p:layoutUnit>
<p:layoutUnit position="south" size="50" header="Bottom"
resizable="true" closable="false" collapsible="true"
collapsed="true">
</p:layoutUnit>
<p:layoutUnit position="west" size="400" header="Inputs"
resizable="true" closable="false" collapsible="true">
<h:form>
<p:commandButton value="Submit" process="@form"
actionListener="#{tableBean.submit}"
update="testFormId,tbl" />
<p:ajaxStatus>
<f:facet name="start">
<h:graphicImage value="/images/ajaxloading.gif" />
</f:facet>
<f:facet name="complete">
<h:outputText value="" />
</f:facet>
</p:ajaxStatus>
</h:form>
</p:layoutUnit>
<p:layoutUnit position="east" size="100" header="Options"
resizable="true" closable="true" collapsible="true" effect="drop"
collapsed="true">
</p:layoutUnit>
<p:layoutUnit position="center">
<h:form id="testFormId">
<p:dataTable id="tbl" var="car" value="#{tableBean.carsSmall}"
paginator="true" rows="10">
<p:column sortBy="#{tableBean.carsSmall}"
filterBy="#{tableBean.carsSmall}">
<f:facet name="header">
<h:outputText value="Model" />
</f:facet>
<h:outputText value="#{car.model}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Year" />
</f:facet>
<h:outputText value="#{car.year}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Manufacturer" />
</f:facet>
<h:outputText value="#{car.manufacturer}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Color" />
</f:facet>
<h:outputText value="#{car.color}" />
</p:column>
</p:dataTable>
<h:panelGrid columns="2">
<p:panel header="Export All Data">
<h:commandLink>
<p:graphicImage value="/images/excel.png" />
<p:dataExporter type="xls" target="tbl" fileName="cars" />
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/pdf.png" />
<p:dataExporter type="pdf" target="tbl" fileName="cars" />
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/csv.png" />
<p:dataExporter type="csv" target="tbl" fileName="cars" />
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/xml.png" />
<p:dataExporter type="xml" target="tbl" fileName="cars" />
</h:commandLink>
</p:panel>
<p:panel header="Export Page Data">
<h:commandLink>
<p:graphicImage value="/images/excel.png" />
<p:dataExporter type="xls" target="tbl" fileName="cars"
pageOnly="true" />
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/pdf.png" />
<p:dataExporter type="pdf" target="tbl" fileName="cars"
pageOnly="true" />
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/csv.png" />
<p:dataExporter type="csv" target="tbl" fileName="cars"
pageOnly="true" />
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/xml.png" />
<p:dataExporter type="xml" target="tbl" fileName="cars"
pageOnly="true" />
</h:commandLink>
</p:panel>
</h:panelGrid>
</h:form>
</p:layoutUnit>
</p:layout>
</h:body>
</f:view>
</html>
Code: Select all
package com.ls.forecast.web.test;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class TableBean implements Serializable {
private static final long serialVersionUID = 7695579230780947616L;
private final static String[] colors;
private final static String[] manufacturers;
private List<Car> carsSmall;
static {
colors = new String[10];
colors[0] = "Black";
colors[1] = "White";
colors[2] = "Green";
colors[3] = "Red";
colors[4] = "Blue";
colors[5] = "Orange";
colors[6] = "Silver";
colors[7] = "Yellow";
colors[8] = "Brown";
colors[9] = "Maroon";
manufacturers = new String[10];
manufacturers[0] = "Mercedes";
manufacturers[1] = "BMW";
manufacturers[2] = "Volvo";
manufacturers[3] = "Audi";
manufacturers[4] = "Renault";
manufacturers[5] = "Opel";
manufacturers[6] = "Volkswagen";
manufacturers[7] = "Chrysler";
manufacturers[8] = "Ferrari";
manufacturers[9] = "Ford";
}
public TableBean() {
}
public void submit() {
carsSmall = new ArrayList<Car>();
populateRandomCars(carsSmall, 9);
}
private void populateRandomCars(List<Car> list, int size) {
for (int i = 0; i < size; i++)
list.add(new Car(getRandomModel(), getRandomYear(),
getRandomManufacturer(), getRandomColor()));
}
public List<Car> getCarsSmall() {
return carsSmall;
}
private int getRandomYear() {
return (int) (Math.random() * 50 + 1960);
}
private String getRandomColor() {
return colors[(int) (Math.random() * 10)];
}
private String getRandomManufacturer() {
return manufacturers[(int) (Math.random() * 10)];
}
private String getRandomModel() {
return UUID.randomUUID().toString().substring(0, 8);
}
public void setCarsSmall(List<Car> carsSmall) {
this.carsSmall = carsSmall;
}
}
Code: Select all
package com.ls.forecast.web.test;
import java.io.Serializable;
public class Car implements Serializable {
/**
*
*/
private static final long serialVersionUID = -4817630746105247261L;
private String model;
private String manufacturer;
private String color;
private int year;
public Car(String model, int year, String manufacturer, String color) {
this.model = model;
this.year = year;
this.manufacturer = manufacturer;
this.color = color;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
}