-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4168547
By: lubosp
I don't want to upload any file but want only the file chooser dialog to be invoked, just like the browse button functionality in the Fileupload dialog.
I am writing my own dialogs that need to browse local files.
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4169487
By: henrichen
That is implemented with HTML tag
<input type="file">
/henri
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4171457
By: lubosp
Thanks Henri,
but how do I call it from onClick event handler (of the Browse... button), and how do I get the result from the <input type="file"> dialog?
I tried:
<attribute name="onClick">
<h:input type="file"/>
</attribute>
but obviously that doesn't work 8-), and I do not have a way to get the data from it.
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4172420
By: henrichen
try
<h:input type="file" onChange="...."/>
/henri
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4174048
By: lubosp
Thanks Henri,
I am almost there. But now I do have a problem to save the value in onChange or zk:onChange. None of them recognizes zk id.
For example (same problem if I use just onChange:
<textbox id="exportlabel" value=""/>
<h:input id="exportfile" type="file" size="50"
zk:onChange="exportlabel.value=self.value"/>
I will get error that exportlabel is unknown.
How do I get the filename from the <h:input type="file">?
Sorry to bother you so much with this and thanks for all your help.
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4174173
By: henrichen
Try use full Java syntax.
self.getFellow("exportlabel").setValue(self.getValue());
/henri
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4174734
By: lubosp
That doesn't work, it fails with error: object doesn't support this property or method (with either zk:onChange or h:onChange).
I only can get the input file value with h:onChange, like this:
<h:input id="exportfile" type="file" size="50"
h:onChange="alert(exportfile.value)"/>
but then I cannot save the value, because h:onChange does not know ZK context/ids:
<label id="exportlabel" value="File to export to:"/> <h:input id="exportfile" type="file" size="50"
h:onChange="exportlabel.value=exportfile.value"/>
I get exportlabel is undefined.
Looking at HTML source, the HTML id for exportlabel is id="_pc6h".
How do I get from h: space to zk: space.
I look at user's guide 2.3 on page 148 example, which uses zk:onChange:
<input id="inp0" type="text" zk:onChange="add()"/> + <input id="inp1" type="text" zk:onChange="add()"/> = <text id="out"/> <zscript> void addItem() { Component li = new Raw("li"); li.setParent(ul); new Text("Item "+ul.getChildren().size()).setParent(li);
}
void add() {
out.setValue(inp0.getValue() + inp1.getValue()); } </zscript>
But that fails for me (inp0, inp1 is not known) but this is zhtml not zul example.
I promise, I will add this to FAQ if we can resolve it 8-).
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4175925
By: henrichen
I tried this on ZK live demo and it works.
/henri
<window title="mix HTML demo" xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:zk="http://www.zkoss.org/2005/zk">
<textbox id="exportlabel" value=""/>
<h:input id="exportfile" type="file" size="50"
zk:onChange="exportlabel.value=self.value"/>
</window>
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4176362
By: lubosp
Thanks Henri,
as always you are right. The problems was the clash of the name spaces. Here is what I had:
xmlns="http://www.zkoss.org/2005/zul"
xmlns:zk="http://www.zkoss.org/2005/zul"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.zkoss.org/2005/zul
http://www.zkoss.org/2005/zul/zul.xsd"
xmlns:h="http://www.w3.org/1999/xhtml"
Notice xmlns="http://www.zkoss.org/2005/zul" and xmlns:zk="http://www.zkoss.org/2005/zul" point to the same namespace and that causes the problem. If I replace it with:
<zk xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:zk="http://www.zkoss.org/2005/zk">
it works! Thanks for all your help and patience.
hi:
I have a proplem about ZK
this is the proplem
SEVERE: >>java.lang.IllegalArgumentException: java.lang.ClassCastException@1134c4b
when we click the upload ,it will appeal. I dont't konw why?
Anybody can help me ,thanks!
<?page title="Upload File" contentType="text/html;charset=UTF-8"?>
<zk>
<zscript><![CDATA[
Component comp;
import org.zkoss.zk.ui.util.Configuration;
]]></zscript>
<borderlayout height="200px">
<west size="10%" border="none"></west>
<center>
<window title="Upload File" border="normal" id="uploadWin"
xmlns:h="http://www.w3.org/1999/xhtml"
apply="com.test.pam.UploadController">
<vbox>
<hbox>
<h:input id="exportfile" type="file" size="30" />
</hbox>
<hbox>
<button label="Upload" id="fileupload">
<attribute name="onClick">
<![CDATA[
Desktop desktop = self.getDesktop();
Configuration conf = desktop.getWebApp().getConfiguration();
conf.setMaxUploadSize(1024);
conf.setUploadCharset("gbk");
]]>
</attribute>
</button>
<button label="Cancel" />
</hbox>
</vbox>
</window>
</center>
<east size="10%" border="none"></east>
</borderlayout>
</zk>
Asked: 2007-02-20 22:35:22 +0800
Seen: 2,229 times
Last updated: Sep 21 '10