gpt4 book ai didi

jsf中ajax化文件上传

转载 作者:行者123 更新时间:2023-12-04 06:00:06 24 4
gpt4 key购买 nike

我想上传文件而不发布整个表单。文件上传工作正常,但提交了整个表单。当验证正确时,这可以正常工作。但是当 p.e.必填字段为空,上传不起作用并返回错误消息(缺少必填字段)
所以我试图ajax文件上传(ajax=true)。但随后上传什么也不做。

我尝试了一种解决方法,将文件上传和其他字段以不同的形式放置。这有效,但结果是您在其他字段中更改的数据在执行文件上传时被忽略。

有什么建议?

这是我使用的代码:

<t:inputFileUpload id="fileupload" value="#{prospectDetail.upFile}" size="50" />
<h:outputLabel for="description" value="#{msg.prospectdetail_description}"/>
<mw:inputText id="description" size="40" value="#{prospectDetail.fileDescription}" />
<p:commandButton styleClass="button" value="#{msg.common_upload}" action="#{prospectDetail.upload}" ajax="false" process="@form" onbegin="busyPopup.show()" oncomplete="busyPopup.hide();"/>

最佳答案

不是 可以通过 XMLHttpRequest 的第一个版本上传文件(这是 JavaScript 中的核心 Ajax 请求 Controller 对象)。 XMLHttpRequest第二版支持它,但这不是由 <p:commandButton> 实现的(并且目前浏览器支持率较低)。

由于您似乎已经在使用 PrimeFaces,为什么不直接使用它自己的 <p:fileUpload> 成分? single upload甚至 auto upload示例应该为您完成(不要忘记在添加 PrimeFaces 的文件上传过滤器后从 web.xml 中删除 MyFaces 扩展过滤器!)。 PrimeFaces' <p:fileUpload>将在可用时自动使用 XHR2 文件上传。

I tried a work around bu putting the file upload and other fields in different forms. This works, but the result is that data you changed in the other fields is disregarded when doing the file upload.



如果将 bean 放入 View 范围而不是请求范围并返回 nullvoid从 Action 方法,那么这应该工作。

关于jsf中ajax化文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9015773/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com