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

发布于 2024-11-08 19:31:06 字数 1160 浏览 2 评论 0原文

我需要通过单击模式窗口上的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文