Daniel Hertz wrote:
Sylvain Wallez wrote:
Et si vous utilisez Cocoon 2.1.8:
uploadWidget.getValue().copyToFile("blah");
Sylvain
Super-bon! Merci à tous pour vos suggestions et code!
J'ai fais:
importPackage(Packages.java.io);
importPackage(Packages.java.util);
importPackage(Packages.java.lang);
cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/Form.js");
function upload() {
var form = new Form("forms/upload_model.xml");
var k = form.showForm("upload-display-pipeline");
k.invalidate();
cocoon.sendPage("upload-success-pipeline.jx",
{
uploadContent: handleUpload(form),
// username: form.lookupWidget("user").getValue(),
filename:
form.lookupWidget("upload").getValue().getHeaders().get("filename")
}
);
}
C'est bizarre d'appeler handleUpload() dans la construction des
paramètres de la vue, alors que cette fonction ne renvoie rien.
Ca serait plus clair (à mon avis) de faire:
var k = form.showForm("upload-display-pipeline");
k.invalidate();
handleUpload(form);
cocoon.sendPage("upload-success-pipeline.jx",
{
// username: form.lookupWidget("user").getValue(),
filename:
form.lookupWidget("upload").getValue().getHeaders().get("filename")
}
);
function handleUpload(form) {
var buf = new java.lang.StringBuffer();
var baseDir = new java.io.File("C:/newdirectory");
var userID = cocoon.session.getAttribute("userID");
var newDir = new java.io.File(baseDir + java.io.File.separator +
userID);
var fileName =
form.lookupWidget("upload").getValue().getHeaders().get("filename");
var uploadWidget = form.lookupWidget("upload");
if (uploadWidget.getValue() != null) {
// test if new directory exists, if not, create it
if (!newDir.exists()) { newDir.mkdirs();
}
uploadWidget.getValue().copyToFile(newDir + java.io.File.separator
+ fileName);
}
}
--
Sylvain Wallez Anyware Technologies
http://bluxte.net http://www.anyware-tech.com
Apache Software Foundation Member Research & Technology Director
---------------------------------------------------------------------
Liste francophone Apache Cocoon -- http://cocoon.apache.org/fr/
Pour vous desinscrire : mailto:[EMAIL PROTECTED]
Autres commandes : mailto:[EMAIL PROTECTED]