james
255 2

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">
<hbox>
</attribute>
</button>
</hbox>
</window>

public void upload(String path) {
try {
if (media != null) {
for (int i = 0; i < media.length; i++) {
Sql sqlForSlash = new Sql();
OutputStream out = new FileOutputStream(this.getCurrentTreePath() + media<i >.getName());
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

delete retag edit

## 4 Replies

deved
114 1

Hi James,

<fileupload onUpload="alert(..)" />

But in your case, you use the Fileupload.get method, so if you need to display a message after the upload process has been completed you can do this:
Media[] media = Fileupload.get(-1);
if (media != null) {
for (int i = 0; i < media.length; i++) {
Sql sqlForSlash = new Sql();
OutputStream out = new FileOutputStream(this.getCurrentTreePath() + media<i >.getName());
out.close();
}
}


Also note that you are registering the "onUpload" event for a button, the button doesn't fire this kind of event.

Regards,
edgar

james
255 2

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>
<hbox>
</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="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>


I have tried the following in my UploadForm.java...
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());


and
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());


This code is placed after the file is uploaded. But I get the following Exception error message...
Fellow component not found: dirTree

Then, if I manually refresh the view, the file is there. But I want the view to be refreshed automatically.

Thank you
-James

deved
114 1

Hi James,
The "dirTree" component is out of the scope of the "uploadWin" component.
You have this:

   <tree id="dirTree"/>


Then you are trying to access with this:
this.getFellow("dirTree")/this.getSpaceOwner().getFellow("dirTree")

I think that the "getSpaceOwner" method on a Window component return the window component itself and because the "dirTree" is not a child of "uploadWin" you get the exception.
Try this: "this.getParent().getFellow("dirTree")" or "this.getParent().getSpaceOwner().getFellow("dirTree")".

Regards,
edgar

james
255 2

Edgar,
Thank you very much. That code worked wonderfully.
this.getParent().getSpaceOwner().getFellow("dirTree") gets the correct component and executes the code correctly.
Thank you again.
-James

[hide preview]