Re: SelectableFolderContent - File Download on click
Yes, It is working. Adding AJAXDownload behavior to the Folder in newContentComponent and download.initiate(target) in onClick method of the Folder implementation did the trick. Thanks, -Mihir. On Thu, Jul 16, 2015 at 2:24 PM, Mihir Chhaya wrote: > I had had AjaxDownLoad implemented as below and download initiated. It > stopped the Ajax debug error, but did not show dialog box to save. > > I might not be setting the resource stream properly. Thanks for 'forcing' > me to look at the AjaxUpload code online :) > > -Mihir. > > On Thu, Jul 16, 2015 at 2:11 PM, Martin Grigorov > wrote: > >> Hi, >> >> You cannot stream binary data in the Ajax response. >> Wicket-ajax.js expects XML response. >> >> Check >> >> https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow >> for a description how to accomplish your task. >> >> Martin Grigorov >> Freelancer. Available for hire! >> Wicket Training and Consulting >> https://twitter.com/mtgrigorov >> >> On Thu, Jul 16, 2015 at 8:36 PM, Mihir Chhaya >> >> wrote: >> >> > Hello, >> > >> > Could anybody guide me on following? >> > >> > I am using SelectableFolderContent from Wicket Advanced Tabular Tree >> > structure example (TableTreePage). >> > >> > Here is what I am trying: >> > >> > 1. Using JCraft - JSch, establish connection to the host, traverse the >> > folder structure, prepare list of file path-name, file size, file type >> etc. >> > - This is working. >> > 2. Display the list on the tabular tree structure - This is working. >> > 3. On click of the link of each folder, expand and collapse the folder >> > structure - Working. >> > 4. On click of the file, zip the file and create into default temp >> folder >> > of the running server- Working. >> > >> > 5. At the same time when clicked, open download file dialog box to >> download >> > the zip file from the server to local machine - Not working. >> > >> > Here is my SelectableFolderContent class. 'downloadFile(...)' method >> call >> > in from select(...) is where I am trying to download using >> IResourceStream. >> > >> > public class SelectableFolderContent extends Content { >> > >> > private static final long serialVersionUID = 1L; >> > >> > private ITreeProvider provider; >> > >> > private IModel selected; >> > >> > public SelectableFolderContent(ITreeProvider >> provider) { >> > this.provider = provider; >> > } >> > >> > @Override >> > public void detach() { >> > if (selected != null) { >> > selected.detach(); >> > } >> > } >> > >> > protected boolean isSelected(SomeFileBean someFile) { >> > IModel model = provider.model(someFile); >> > >> > try { >> > return selected != null && selected.equals(model); >> > } finally { >> > model.detach(); >> > } >> > } >> > >> > protected void select(SomeFileBean someFile, >> AbstractTree >> > tree, final AjaxRequestTarget target) { >> > >> > if (!someFile.isFolder()) { >> > //SFTP to host, get file, create zip in temp folder. Once done, >> download to >> > local machine. >> > downloadFile(tree.getPage(), someFile, target); >> > } else { >> > >> > if (selected != null) { >> > tree.updateNode(selected.getObject(), target); >> > >> > selected.detach(); >> > selected = null; >> > } >> > >> > selected = provider.model(someFile); >> > >> > if (tree.getState(selected.getObject()) == >> > AbstractTree.State.COLLAPSED) { >> > tree.expand(selected.getObject()); >> > } else { >> > tree.collapse(selected.getObject()); >> > } >> > tree.updateNode(someFile, target); >> > >> > tree.getPage().setResponsePage(SomeTableTreePage.class); >> > } >> > } >> > >> > >> > @Override >> > public Component newContentComponent(final String id, final >> > AbstractTree tree, final IModel model) { >> > >> > Folder components = new Folder(id, >> > tree, model) { >> > private static final long serialVersionUID = 1L; >> > >> > @Override >> > protected IModel newLabelModel(IModel >> model) { >> > return new PropertyModel(model, "id"); >> > } >> > >> > /** >> > * Always clickable. >> > */ >> > @Override >> > protected boolean isClickable() { >> > return true; >> > } >> > >> > @Override >> > protected void onClick(AjaxRequestTarget target) { >> > SelectableFolderContent.this.select(modelObject, tree, >> > target); >> > } >> > >> > @Override >> > protected boolean isSelected() { >> > return >> > SelectableFolderContent.this.isSelected(getModelObject()); >> > } >>
Re: SelectableFolderContent - File Download on click
I had had AjaxDownLoad implemented as below and download initiated. It stopped the Ajax debug error, but did not show dialog box to save. I might not be setting the resource stream properly. Thanks for 'forcing' me to look at the AjaxUpload code online :) -Mihir. On Thu, Jul 16, 2015 at 2:11 PM, Martin Grigorov wrote: > Hi, > > You cannot stream binary data in the Ajax response. > Wicket-ajax.js expects XML response. > > Check > > https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow > for a description how to accomplish your task. > > Martin Grigorov > Freelancer. Available for hire! > Wicket Training and Consulting > https://twitter.com/mtgrigorov > > On Thu, Jul 16, 2015 at 8:36 PM, Mihir Chhaya > wrote: > > > Hello, > > > > Could anybody guide me on following? > > > > I am using SelectableFolderContent from Wicket Advanced Tabular Tree > > structure example (TableTreePage). > > > > Here is what I am trying: > > > > 1. Using JCraft - JSch, establish connection to the host, traverse the > > folder structure, prepare list of file path-name, file size, file type > etc. > > - This is working. > > 2. Display the list on the tabular tree structure - This is working. > > 3. On click of the link of each folder, expand and collapse the folder > > structure - Working. > > 4. On click of the file, zip the file and create into default temp folder > > of the running server- Working. > > > > 5. At the same time when clicked, open download file dialog box to > download > > the zip file from the server to local machine - Not working. > > > > Here is my SelectableFolderContent class. 'downloadFile(...)' method call > > in from select(...) is where I am trying to download using > IResourceStream. > > > > public class SelectableFolderContent extends Content { > > > > private static final long serialVersionUID = 1L; > > > > private ITreeProvider provider; > > > > private IModel selected; > > > > public SelectableFolderContent(ITreeProvider provider) > { > > this.provider = provider; > > } > > > > @Override > > public void detach() { > > if (selected != null) { > > selected.detach(); > > } > > } > > > > protected boolean isSelected(SomeFileBean someFile) { > > IModel model = provider.model(someFile); > > > > try { > > return selected != null && selected.equals(model); > > } finally { > > model.detach(); > > } > > } > > > > protected void select(SomeFileBean someFile, > AbstractTree > > tree, final AjaxRequestTarget target) { > > > > if (!someFile.isFolder()) { > > //SFTP to host, get file, create zip in temp folder. Once done, download > to > > local machine. > > downloadFile(tree.getPage(), someFile, target); > > } else { > > > > if (selected != null) { > > tree.updateNode(selected.getObject(), target); > > > > selected.detach(); > > selected = null; > > } > > > > selected = provider.model(someFile); > > > > if (tree.getState(selected.getObject()) == > > AbstractTree.State.COLLAPSED) { > > tree.expand(selected.getObject()); > > } else { > > tree.collapse(selected.getObject()); > > } > > tree.updateNode(someFile, target); > > > > tree.getPage().setResponsePage(SomeTableTreePage.class); > > } > > } > > > > > > @Override > > public Component newContentComponent(final String id, final > > AbstractTree tree, final IModel model) { > > > > Folder components = new Folder(id, > > tree, model) { > > private static final long serialVersionUID = 1L; > > > > @Override > > protected IModel newLabelModel(IModel > model) { > > return new PropertyModel(model, "id"); > > } > > > > /** > > * Always clickable. > > */ > > @Override > > protected boolean isClickable() { > > return true; > > } > > > > @Override > > protected void onClick(AjaxRequestTarget target) { > > SelectableFolderContent.this.select(modelObject, tree, > > target); > > } > > > > @Override > > protected boolean isSelected() { > > return > > SelectableFolderContent.this.isSelected(getModelObject()); > > } > > > > }; > > > > return components; > > } > > protected void downloadFile(final Page page, SomeFileBean someFile, > > AjaxRequestTarget target) { > > IModel fileModel = getDownloadFileModel(someFile); > > file = fileModel.getObject(); > > IResourceStream resourceStream = new FileResourceStream(new > > org.apache.wicket.util.file.File(file)); > > String fileName =
Re: SelectableFolderContent - File Download on click
Hi, You cannot stream binary data in the Ajax response. Wicket-ajax.js expects XML response. Check https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow for a description how to accomplish your task. Martin Grigorov Freelancer. Available for hire! Wicket Training and Consulting https://twitter.com/mtgrigorov On Thu, Jul 16, 2015 at 8:36 PM, Mihir Chhaya wrote: > Hello, > > Could anybody guide me on following? > > I am using SelectableFolderContent from Wicket Advanced Tabular Tree > structure example (TableTreePage). > > Here is what I am trying: > > 1. Using JCraft - JSch, establish connection to the host, traverse the > folder structure, prepare list of file path-name, file size, file type etc. > - This is working. > 2. Display the list on the tabular tree structure - This is working. > 3. On click of the link of each folder, expand and collapse the folder > structure - Working. > 4. On click of the file, zip the file and create into default temp folder > of the running server- Working. > > 5. At the same time when clicked, open download file dialog box to download > the zip file from the server to local machine - Not working. > > Here is my SelectableFolderContent class. 'downloadFile(...)' method call > in from select(...) is where I am trying to download using IResourceStream. > > public class SelectableFolderContent extends Content { > > private static final long serialVersionUID = 1L; > > private ITreeProvider provider; > > private IModel selected; > > public SelectableFolderContent(ITreeProvider provider) { > this.provider = provider; > } > > @Override > public void detach() { > if (selected != null) { > selected.detach(); > } > } > > protected boolean isSelected(SomeFileBean someFile) { > IModel model = provider.model(someFile); > > try { > return selected != null && selected.equals(model); > } finally { > model.detach(); > } > } > > protected void select(SomeFileBean someFile, AbstractTree > tree, final AjaxRequestTarget target) { > > if (!someFile.isFolder()) { > //SFTP to host, get file, create zip in temp folder. Once done, download to > local machine. > downloadFile(tree.getPage(), someFile, target); > } else { > > if (selected != null) { > tree.updateNode(selected.getObject(), target); > > selected.detach(); > selected = null; > } > > selected = provider.model(someFile); > > if (tree.getState(selected.getObject()) == > AbstractTree.State.COLLAPSED) { > tree.expand(selected.getObject()); > } else { > tree.collapse(selected.getObject()); > } > tree.updateNode(someFile, target); > > tree.getPage().setResponsePage(SomeTableTreePage.class); > } > } > > > @Override > public Component newContentComponent(final String id, final > AbstractTree tree, final IModel model) { > > Folder components = new Folder(id, > tree, model) { > private static final long serialVersionUID = 1L; > > @Override > protected IModel newLabelModel(IModel model) { > return new PropertyModel(model, "id"); > } > > /** > * Always clickable. > */ > @Override > protected boolean isClickable() { > return true; > } > > @Override > protected void onClick(AjaxRequestTarget target) { > SelectableFolderContent.this.select(modelObject, tree, > target); > } > > @Override > protected boolean isSelected() { > return > SelectableFolderContent.this.isSelected(getModelObject()); > } > > }; > > return components; > } > protected void downloadFile(final Page page, SomeFileBean someFile, > AjaxRequestTarget target) { > IModel fileModel = getDownloadFileModel(someFile); > file = fileModel.getObject(); > IResourceStream resourceStream = new FileResourceStream(new > org.apache.wicket.util.file.File(file)); > String fileName = "serverlog.zip"; > > ResourceStreamRequestHandler resourceStreamRequestHandler = new > ResourceStreamRequestHandler( > resourceStream, fileName); > > > page.getRequestCycle().scheduleRequestHandlerAfterCurrent(resourceStreamRequestHandler); > > > try { > resourceStream.close(); > } catch (IOException e) { > AppLogger.logMessage(AppLogger.LEVEL.ERROR, "File I/O Error:", > e); > } catch (Exception e) { > AppLogger.logMessage(AppLogger.LEVEL.ERROR, "Error:", e); > } > } > } > > > There are two issues I am experiencing: > 1. Dia
SelectableFolderContent - File Download on click
Hello, Could anybody guide me on following? I am using SelectableFolderContent from Wicket Advanced Tabular Tree structure example (TableTreePage). Here is what I am trying: 1. Using JCraft - JSch, establish connection to the host, traverse the folder structure, prepare list of file path-name, file size, file type etc. - This is working. 2. Display the list on the tabular tree structure - This is working. 3. On click of the link of each folder, expand and collapse the folder structure - Working. 4. On click of the file, zip the file and create into default temp folder of the running server- Working. 5. At the same time when clicked, open download file dialog box to download the zip file from the server to local machine - Not working. Here is my SelectableFolderContent class. 'downloadFile(...)' method call in from select(...) is where I am trying to download using IResourceStream. public class SelectableFolderContent extends Content { private static final long serialVersionUID = 1L; private ITreeProvider provider; private IModel selected; public SelectableFolderContent(ITreeProvider provider) { this.provider = provider; } @Override public void detach() { if (selected != null) { selected.detach(); } } protected boolean isSelected(SomeFileBean someFile) { IModel model = provider.model(someFile); try { return selected != null && selected.equals(model); } finally { model.detach(); } } protected void select(SomeFileBean someFile, AbstractTree tree, final AjaxRequestTarget target) { if (!someFile.isFolder()) { //SFTP to host, get file, create zip in temp folder. Once done, download to local machine. downloadFile(tree.getPage(), someFile, target); } else { if (selected != null) { tree.updateNode(selected.getObject(), target); selected.detach(); selected = null; } selected = provider.model(someFile); if (tree.getState(selected.getObject()) == AbstractTree.State.COLLAPSED) { tree.expand(selected.getObject()); } else { tree.collapse(selected.getObject()); } tree.updateNode(someFile, target); tree.getPage().setResponsePage(SomeTableTreePage.class); } } @Override public Component newContentComponent(final String id, final AbstractTree tree, final IModel model) { Folder components = new Folder(id, tree, model) { private static final long serialVersionUID = 1L; @Override protected IModel newLabelModel(IModel model) { return new PropertyModel(model, "id"); } /** * Always clickable. */ @Override protected boolean isClickable() { return true; } @Override protected void onClick(AjaxRequestTarget target) { SelectableFolderContent.this.select(modelObject, tree, target); } @Override protected boolean isSelected() { return SelectableFolderContent.this.isSelected(getModelObject()); } }; return components; } protected void downloadFile(final Page page, SomeFileBean someFile, AjaxRequestTarget target) { IModel fileModel = getDownloadFileModel(someFile); file = fileModel.getObject(); IResourceStream resourceStream = new FileResourceStream(new org.apache.wicket.util.file.File(file)); String fileName = "serverlog.zip"; ResourceStreamRequestHandler resourceStreamRequestHandler = new ResourceStreamRequestHandler( resourceStream, fileName); page.getRequestCycle().scheduleRequestHandlerAfterCurrent(resourceStreamRequestHandler); try { resourceStream.close(); } catch (IOException e) { AppLogger.logMessage(AppLogger.LEVEL.ERROR, "File I/O Error:", e); } catch (Exception e) { AppLogger.logMessage(AppLogger.LEVEL.ERROR, "Error:", e); } } } There are two issues I am experiencing: 1. Dialog box not opening to save the file on local machine. 2. When debugging, the Ajax Debug window showing 'Wicket.Ajax.Call.failure: Error while parsing response: Error: Invalid XML' error. Thanks in advance, -Mihir.