Java PrimeFaces 3.0.M4文件上传的另一个难题
因此,这个问题相当普遍。我想使用Java PrimeFaces 3.0.M4文件上传的另一个难题,java,jakarta-ee,file-upload,primefaces,Java,Jakarta Ee,File Upload,Primefaces,因此,这个问题相当普遍。我想使用mode=“simple”()中的p:fileUpload将文件上载到服务器。关于论坛上传文件的问题,有很多问题和答案,但我没有找到一个全面的答案。文件上载组件位于/faces/second.xhtml: <h:form> <p:wizard> <p:tab id="firstStep" title="First step"> <ui:include src="/faces/
mode=“simple”
()中的p:fileUpload
将文件上载到服务器。关于论坛上传文件的问题,有很多问题和答案,但我没有找到一个全面的答案。文件上载组件位于/faces/second.xhtml
:
<h:form>
<p:wizard>
<p:tab id="firstStep" title="First step">
<ui:include src="/faces/first.xhtml" />
</p:tab>
<p:tab name="secondStep" title="Second step">
<ui:include src="/faces/second.xhtml" />
</p:tab>
</p:wizard>
</h:form>
<!-- PrimeFaces file upload -->
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>100000</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>C:\Users\name\Desktop\</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
豆子:
@SessionScoped
public class TutorialBean {
private UploadedFile thumbnail;
public void thumbnailUpload(){
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,
"File uploaded", thumbnail.getFileName());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
// setters and getters
}
我已将文件上载筛选器添加到web.xml
:
<h:form>
<p:wizard>
<p:tab id="firstStep" title="First step">
<ui:include src="/faces/first.xhtml" />
</p:tab>
<p:tab name="secondStep" title="Second step">
<ui:include src="/faces/second.xhtml" />
</p:tab>
</p:wizard>
</h:form>
<!-- PrimeFaces file upload -->
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>100000</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>C:\Users\name\Desktop\</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
PrimeFaces文件上载筛选器
org.primefaces.webapp.filter.FileUploadFilter
阈值大小
100000
上传目录
C:\Users\name\Desktop\
PrimeFaces文件上载筛选器
Facesservlet
我在我的pom.xml
中添加了commons io
(2.0.1)和commons fileupload
(1.2.2)。根据解决方案,我发现它必须工作,但它不工作<代码>缩略图在thumbnailUpload
执行期间为null
。
我使用primefaces 3.0.M4,jBoss作为7.0.2.Final
提前谢谢
已解决:问题不在
fileUpload
组件中,而是在作为主页一部分包含的页面中。我已经在内部表单中添加了prependId=“false”
,一切正常首先尝试使用简单/标准Primefaces过滤器:
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
更新:
因为在第二步中只有文件上传,所以您可以尝试这样的方法
<p:wizard>
<p:tab id="firstStep" title="First step">
<h:form>
<ui:include src="/faces/first.xhtml" />
</h:form>
</p:tab>
<p:tab name="secondStep" title="Second step">
<p:panel>
<h:form multipart>
<h:panelGrid columns="2" id="file">
<p:fileUpload value="#{tutorialBean.thumbnail}" mode="simple" />
<p:commandButton value="Submit" update="growl"
actionListener="#{tutorialBean.thumbnailUpload}" />
</h:panelGrid>
</h:form>
</p:panel>
</p:tab>
</p:wizard>
首先尝试使用简单/标准Primefaces过滤器:
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
更新:
因为在第二步中只有文件上传,所以您可以尝试这样的方法
<p:wizard>
<p:tab id="firstStep" title="First step">
<h:form>
<ui:include src="/faces/first.xhtml" />
</h:form>
</p:tab>
<p:tab name="secondStep" title="Second step">
<p:panel>
<h:form multipart>
<h:panelGrid columns="2" id="file">
<p:fileUpload value="#{tutorialBean.thumbnail}" mode="simple" />
<p:commandButton value="Submit" update="growl"
actionListener="#{tutorialBean.thumbnailUpload}" />
</h:panelGrid>
</h:form>
</p:panel>
</p:tab>
</p:wizard>
嵌套表单中似乎存在问题。我不知道如何在另一个主表单中使用文件上载。你有什么建议吗?@nikagra在这里发布(更新/编辑问题)你的整个xhtml页面,看看你是否真的需要“嵌套表单”…也许你可以关闭一个表单,然后打开另一个表单。因此,问题似乎出在表单和ui:include
。我已经更新了question@nikagra似乎文件上传应该在版本3中工作。看看这个已解决的问题:这个主题可能会有所帮助:看起来嵌套表单中存在问题。我不知道如何在另一个主表单中使用文件上载。你有什么建议吗?@nikagra在这里发布(更新/编辑问题)你的整个xhtml页面,看看你是否真的需要“嵌套表单”…也许你可以关闭一个表单,然后打开另一个表单。因此,问题似乎出在表单和ui:include
。我已经更新了question@nikagra似乎文件上传应该在版本3中工作。看看这个已结束的问题:这个主题可能会有所帮助: