- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想上传文件而不发布整个表单。文件上传工作正常,但提交了整个表单。当验证正确时,这可以正常工作。但是当 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.
null
或
void
从 Action 方法,那么这应该工作。
关于jsf中ajax化文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9015773/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!