Wicket:在模态窗口中使用 AJAX 上传文件
我需要通过单击模式窗口上的 Ajax 按钮来执行文件上传。我遇到问题,因为文件已上传,但上传过程尚未完成,并且无法使用文件名更新表单。有文件上传后无法隐藏的AjaxIndicator。模式窗口作为面板实现。这是代码:
uploadFile=new IndicatingAjaxButton("uploadFile"){
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
uploadFile.getAjaxIndicatorMarkupId();
FileUpload fileUpload =
((FileUploadFieldPanel)uploadPanel).getUploadField().getFileUpload();
if (fileUpload != null)
{
String fileName = fileUpload.getClientFileName();
String path = uploadpath + relativeuploadpath;
File newFile = new File(path, fileName);
checkFileExists(newFile);
try {
newFile.createNewFile();
fileUpload.writeTo(newFile);
}
catch (IOException e) {
e.printStackTrace();
}
titleField.setModelObject(fileName);
target.addComponent(titleField);
}
};
uploadFile.setOutputMarkupId(true);
form.add(uploadFile);
问题是:如何使用 fileName 更新表单上的 titleField?在本例中为“target.addComponent(titleField);”不起作用。
I need to perform the file upload by clicking on the Ajax button on modal window. I have the problem, because the file is uploaded, but the process of uploading is not finished and the form can't be updated with the fileName. There is the AjaxIndicator that can't be hided after the file is uploaded. The modal window is implemented as a Panel. Here is the code:
uploadFile=new IndicatingAjaxButton("uploadFile"){
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
uploadFile.getAjaxIndicatorMarkupId();
FileUpload fileUpload =
((FileUploadFieldPanel)uploadPanel).getUploadField().getFileUpload();
if (fileUpload != null)
{
String fileName = fileUpload.getClientFileName();
String path = uploadpath + relativeuploadpath;
File newFile = new File(path, fileName);
checkFileExists(newFile);
try {
newFile.createNewFile();
fileUpload.writeTo(newFile);
}
catch (IOException e) {
e.printStackTrace();
}
titleField.setModelObject(fileName);
target.addComponent(titleField);
}
};
uploadFile.setOutputMarkupId(true);
form.add(uploadFile);
The question is: how can I update the titleField on the form with the fileName? In this case "target.addComponent(titleField);" doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎有一个关于此问题的教程 http://www.doorient.com/blog/2008/04/23/wicket-ajax-like-file-upload-on-a-modal-window/。
There seems to be a tutorial concerning this issue at http://www.dooriented.com/blog/2008/04/23/wicket-ajax-like-file-upload-on-a-modal-window/.