我在Tomcat 7.0上使用javax-faces-2.2.1并尝试让文件上传工作。
添加h:inputFile会抛出一个错误,表示表单需要是多部分的,但是解析了支持bean。添加enctype =“multipart / form-data会抛出一个错误,指出当bean标识符解析为null时bean无法访问。
当我使用JSF 2.2时,我理解我不需要在web.xml中定义过滤器,而且我不需要将commons-fileupload添加到lib
页面的相关位是
<h:html xmlns="http://www.w3c.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jstl/core">
<ui:composition template="/zuzztemplate.xhtml">
<ui:define name="body">
<h:form id="page-form" prependId="false" enctype="multipart/form-data" >
和
<rich:tab name="Photos" >
<h:panelGrid columns="1">
<h:panelGrid columns="2" columnClasses="field-label,field-value">
<h:outputLabel for="caption" value="Caption:" styleClass="form-label" />
<h:inputText id="caption" value="#{galleryBean.photoCaption}" size="50" />
</h:panelGrid>
<h:inputFile id="file" value="#{galleryBean.uploadFile}"/>
<h:commandButton value="Upload" action="#{galleryBean.upload}" ajax="false"/>
</h:panelGrid>
</rich:tab>
支持bean用
注释@ManagedBean
@SessionScoped
public class GalleryBean extends BaseBean {
模板中没有表格,h:head和h:body使用