target.add(importFeedback);
}
});
// Add a component to download a file without page refresh
final AjaxDownload download = new AjaxDownload();
langForm.add(download);
langForm.add(new AjaxButton("export"){
private static final long serialVersionUID = 1L;
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
final List<Fieldlanguagesvalues> flvList = getBean(FieldLanguagesValuesDao.class).getMixedFieldValuesList(language.getLanguage_id());
FieldLanguage fl = getBean(FieldLanguageDao.class).getFieldLanguageById(language.getLanguage_id());
if (fl != null && flvList != null) {
download.setFileName(fl.getName() + ".xml");
download.setResourceStream(new AbstractResourceStream() {
private static final long serialVersionUID = 1L;
private StringWriter sw;
private InputStream is;
public InputStream getInputStream() throws ResourceStreamNotFoundException {
try {
Document doc = createDocument(flvList, getBean(FieldLanguagesValuesDao.class).getUntranslatedFieldValuesList(language.getLanguage_id()));
sw = new StringWriter();
LangExport.serializetoXML(sw, "UTF-8", doc);
is = new ByteArrayInputStream(sw.toString().getBytes());
return is;
} catch (Exception e) {
throw new ResourceStreamNotFoundException(e);
}
}
public void close() throws IOException {
if (is != null) {
is.close();
is = null;
}
sw = null;
}
});//new FileResourceStream(new File(requestedFile)));
download.initiate(target);
}
// repaint the feedback panel so that it is hidden
target.add(importFeedback);
}