我正在使用 myfaces ExtensionFilter 上传文件,但该文件未设置为我的 bean 以进行进一步处理。
这是代码:
<h:form id="uploadFileForm" enctype="multipart/form-data">
<tom:inputFileUpload id="file"
value="#{paramUpload.uploadFile}">
<f:valueChangeListener type="com.bosch.de.plcd.plugin.ParamFileUpload" />
</tom:inputFileUpload>
<a4j:commandButton value="#{tpMsgs.upload}"
styleClass="button" action="#{paramUpload.uploadParamFile}"
onclick="javascript:updateParentScreen();">
</a4j:commandButton>
</h:form>
和 web.xml 配置如下
<filter>
<filter-name>Extensions Filter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Extensions Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
由于UploadFile
未设置为 bean,因此我也尝试使用 ValueChangeListener,不过如此,它不是 bean :)
豆码
public class ParamFileUpload implements ValueChangeListener {
private UploadedFile uploadFile;
public void uploadParamFile() {
if(uploadFile != null) {
LOGGER.info("File type: " + uploadFile.getContentType());
LOGGER.info("File name: " + uploadFile.getName());
LOGGER.info("File size: " + uploadFile.getSize() + " bytes");
}
}
public UploadedFile getUploadFile() {
return uploadFile;
}
public void setUploadFile(UploadedFile uploadFile) {
this.uploadFile = (UploadedFile)uploadFile;
}
public void processValueChange(ValueChangeEvent event)
throws AbortProcessingException {
this.uploadFile = (UploadedFile) event.getNewValue();
}
}
您是否看到我在这里可能缺少的任何其他配置?