-
FEATURED COMPONENTS
First time here? Check out the FAQ!
1 | initial version | |
Oke,
Had this problem myself and found the solution for it :
<button label="Export" onClick="@command('renderMeshElementAndExport', ref=activitytrainingslb, name='someExcelName')"/>
or
<button label="Export" onClick="@command('renderMeshElementAndExport', ref=activitytrainingslb)"/>
@Command
public void renderMeshElementAndExport(@ContextParam(ContextType.BINDER) Binder binder, @BindingParam("ref") MeshElement meshElement,
@BindingParam("name") String name) throws Exception {
if (meshElement instanceof Grid) {
((Grid) meshElement).renderAll();
} else if (meshElement instanceof Listbox) {
((Listbox) meshElement).renderAll();
}
Map<String, Object> args = new HashMap<String, Object>();
args.put("ref", meshElement);
args.put("name", name);
binder.postCommand("exportMeshElementToExcel", args);
}
@Command
public void exportMeshElementToExcel(@BindingParam("ref") MeshElement meshElement, @BindingParam("name") String name)
throws Exception {
if (meshElement instanceof Listbox || meshElement instanceof Grid) {
if (name == null) {
name = meshElement.getParent().getPage().getTitle() == null ? "excelsheet" : meshElement.getParent().getPage().getTitle();
}
ByteArrayOutputStream out = export(meshElement);
logger.debug("file size : " + out.size());
AMedia amedia = new AMedia(name + ".xlsx", "xls", "application/file",
out.toByteArray());
Filedownload.save(amedia);
IOUtils.closeQuietly(out);
} else {
throw new IllegalArgumentException("We can only export grid or listbox");
}
}
private ByteArrayOutputStream export(MeshElement meshElement) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ExcelExporter exporter = new ExcelExporter();
exporter.export(meshElement, out);
return out;
}
2 | No.2 Revision |
Oke,
Had this problem myself and found the solution for it :
<button label="Export" onClick="@command('renderMeshElementAndExport', ref=activitytrainingslb, ref=idListboxOrGrid, name='someExcelName')"/>
or
<button label="Export" onClick="@command('renderMeshElementAndExport', ref=activitytrainingslb)"/>
ref=idListboxOrGrid)"/>
@Command
public void renderMeshElementAndExport(@ContextParam(ContextType.BINDER) Binder binder, @BindingParam("ref") MeshElement meshElement,
@BindingParam("name") String name) throws Exception {
if (meshElement instanceof Grid) {
((Grid) meshElement).renderAll();
} else if (meshElement instanceof Listbox) {
((Listbox) meshElement).renderAll();
}
Map<String, Object> args = new HashMap<String, Object>();
args.put("ref", meshElement);
args.put("name", name);
binder.postCommand("exportMeshElementToExcel", args);
}
@Command
public void exportMeshElementToExcel(@BindingParam("ref") MeshElement meshElement, @BindingParam("name") String name)
throws Exception {
if (meshElement instanceof Listbox || meshElement instanceof Grid) {
if (name == null) {
name = meshElement.getParent().getPage().getTitle() == null ? "excelsheet" : meshElement.getParent().getPage().getTitle();
}
ByteArrayOutputStream out = export(meshElement);
logger.debug("file size : " + out.size());
AMedia amedia = new AMedia(name + ".xlsx", "xls", "application/file",
out.toByteArray());
Filedownload.save(amedia);
IOUtils.closeQuietly(out);
} else {
throw new IllegalArgumentException("We can only export grid or listbox");
}
}
private ByteArrayOutputStream export(MeshElement meshElement) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ExcelExporter exporter = new ExcelExporter();
exporter.export(meshElement, out);
return out;
}