【发布时间】:2011-11-15 16:56:10
【问题描述】:
所以,这个问题非常普遍。我想在mode="simple" (showcase) 中使用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>
其中/faces/second.xhtml 包含:
<p:panel>
<h:panelGrid columns="2" id="file">
<p:fileUpload value="#{tutorialBean.thumbnail}" mode="simple" />
<p:commandButton value="Submit" update="growl"
actionListener="#{tutorialBean.thumbnailUpload}" />
</h:panelGrid>
</p:panel>
豆子:
@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
}
我已将 FileUpload 过滤器添加到 web.xml:
<!-- 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>
我已将commons-io (2.0.1) 和commons-fileupload (1.2.2) 添加到我的pom.xml。根据我发现它必须工作的解决方案,但它没有。 thumbnail 在 thumbnailUpload 执行期间是 null。
我正在使用 primefaces 3.0.M4,jBoss 作为 7.0.2.Final
提前致谢
已解决: 问题不在fileUpload 组件中,而是在作为主页一部分包含的页面表单中。我已将prependId="false" 添加到内部表单中,一切正常
【问题讨论】:
标签: java jakarta-ee file-upload primefaces