First time here? Check out the FAQ!
In a grid, I am displaying the file contents of a folder.
I want to refresh the display when I upload a file.
I was trying to use the onUpload event, but it doesn't do anything.
sample code from file.zul
<window id="uploadWin" width="200px" border="normal" use="com.UploadForm"> <caption label="Upload Files" /> <hbox> <button label="Upload" onClick="uploadWin.upload(uploadPath)"> <attribute name="onUpload"> alert("file has been uploaded"); </attribute> </button> </hbox> </window>
public void upload(String path) { try { Media[] media = Fileupload.get(-1); if (media != null) { for (int i = 0; i < media.length; i++) { String uploadedfile = media<i >.getStringData(); Sql sqlForSlash = new Sql(); OutputStream out = new FileOutputStream(this.getCurrentTreePath() + media<i >.getName()); out.write(uploadedfile.getBytes()); out.close(); } } } catch (Exception e) { showError("ERROR " + e.getMessage()); } }
When I use this, I get no alert/message box. The file uploads just fine, no problems. But the onUpload Event is obviously not called.
Does anyone know of something I can do or use to execute code when I upload a file?
Thanks to everyone who takes the time to look at this, and I greatly appreciate any help I can get.
-James
Hi James,
The "onUpload" event is available if you use the fileupload component:
<fileupload onUpload="alert(..)" />
Media[] media = Fileupload.get(-1); if (media != null) { for (int i = 0; i < media.length; i++) { String uploadedfile = media<i >.getStringData(); Sql sqlForSlash = new Sql(); OutputStream out = new FileOutputStream(this.getCurrentTreePath() + media<i >.getName()); out.write(uploadedfile.getBytes()); out.close(); } } Messagebox.show("file has been uploaded");
Regards,
edgar
Thanks Edgar.
(The message to be displayed was only for testing, to see if the event even occured.)
In that case I have another question, how would I be able to interact with tree and grid components?
file.zul
<hbox> <vbox> <tree width="250px" id="dirTree" Zclass="z-filetree"> <attribute name="onSelect"> if (!dirTree.getSelectedItem().getValue().equals("")){ main.setCurrentTreePath(dirTree.getSelectedItem().getValue().toString()); ArrayList fileDataList = main.fileDataList(dirTree.getSelectedItem().getValue().toString()); ListModel fileDataListModel = new SimpleListModel(fileDataList.toArray()); viewGrid.setModel(fileDataListModel); viewGrid.setRowRenderer(new dir_cont.FilelistRowRenderer()); } </attribute> </tree> <window id="uploadWin" width="200px" border="normal" use="com.UploadForm"> <caption label="Upload Files" /> <hbox> <button label="Upload" onClick="uploadWin.upload(uploadPath)"> <attribute name="onUpload"> alert("file has been uploaded"); </attribute> </button> </hbox> </window> </vbox><vbox> <grid id="viewGrid" mold="paging" pageSize="30" pagingPosition="both"> <columns sizable="true"> <column label="File Name" width="260px" /> <column label="Download" width="70px" align="center" /> <column label="Delete" width="60px" align="center" /> <column label="File Size" width="70px" align="right"/> </columns> </grid> <zscript> dirTree.setModel(main.createDirectoryTreeModel()); dirTree.setTreeitemRenderer(new dir_tree.DirTreeitemRenderer()); </zscript> </vbox> </hbox>
ArrayList<Filelist> fileDataList = sqlClass.fileDataList(((Tree) this.getFellow("dirTree")).getSelectedItem().getValue().toString()); ListModel fileDataListModel = new SimpleListModel(fileDataList.toArray()); ((Grid) this.getFellow("viewGrid")).setModel(fileDataListModel); ((Grid) this.getFellow("viewGrid")).setRowRenderer(new FilelistRowRenderer());
ArrayList<dir_cont.Filelist> fileDataList = sqlClass.fileDataList(((Tree) this.getSpaceOwner().getFellow("dirTree")).getSelectedItem().getValue().toString()); ListModel fileDataListModel = new SimpleListModel(fileDataList.toArray()); ((Grid) this.getSpaceOwner().getFellow("viewGrid")).setModel(fileDataListModel); ((Grid) this.getSpaceOwner().getFellow("viewGrid")).setRowRenderer(new dir_cont.FilelistRowRenderer());
Fellow component not found: dirTree
Anyone have any ideas or suggestions about this?
Thank you
-James
Hi James,
The "dirTree" component is out of the scope of the "uploadWin" component.
You have this:
<tree id="dirTree"/> <window id="uploadWin">
this.getFellow("dirTree")/this.getSpaceOwner().getFellow("dirTree")
Regards,
edgar
Asked: 2009-06-22 21:05:08 +0800
Seen: 534 times
Last updated: Jun 22 '09