Wicket:在模态窗口中使用AJAX上传文件

时间:2011-05-22 15:05:04

标签: ajax file-upload wicket

我需要通过单击模态窗口上的Ajax按钮来执行文件上传。我有问题,因为文件已上传,但上传过程未完成,并且无法使用fileName更新表单。上传文件后无法隐藏AjaxIndicator。模态窗口实现为Panel。这是代码:

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);”不起作用。

1 个答案:

答案 0 :(得分:0)