0
我得到的文件空值上传我的代码如下....请让我知道什么是缺少Primefaces +春文件上传
@Component("businessInformationBean")
@Scope("view")
public class BusinessInformationBean extends AbstractBaseBean {
private static final Logger LOGGER = Logger
.getLogger(BusinessInformationBean.class);
private static final long serialVersionUID = 1L;
@Autowired
private BusinessInformationService businessInformationService;
@Value("#{addressBean}")
private AddressBean address;
private String firmName;
private Date openingDate;
private Date activityDate;
private String businessType;
private Date seasonStartDate;
private Date seasonEndDate;
private Date closerDate;
private String natureOfBusiness;
private UploadedFile file;
private String bankAccholdername;
private String bankName;
private String bankBranchName;
private String accountNumber;
private String accountType;
private String bankAddress;
private String bankIFSCCode;
private String bankCity;
private String bankDistrict;
private String bankState;
private Integer bankZipcode;
public void save(ActionEvent event) {
LOGGER.info("businessInformationBean Save");
try
{
FacesContext fc = getFacesContext();
if (frmValidation())
{
MmBusinessInformation businessInformation = businessInformationService
.fetchBusinessInformationServiceByLoginUser(getCurrentUser());
mapWebBackToDomain(businessInformation);
businessInformationService.saveOrUpdate(businessInformation);
renderRecordSaveMessage();
}
else
{
fc.renderResponse();
}
}
catch (Exception e)
{
LOGGER.error(e.getMessage());
renderFatalError();
}
}
public UploadedFile getFile() {
return file;
}
public void setFile(UploadedFile file) {
this.file = file;
}
我的web.xml低于:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>ems-web</display-name>
<welcome-file-list>
<welcome-file>login.xhtml</welcome-file>
</welcome-file-list>
<!-- Change to "Production" when you are ready to deploy -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>redmond</param-value>
</context-param>
<!-- Spring Security Facelets Tag Library -->
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
</context-param>
<context-param>
<param-name>primefaces.FONT_AWESOME</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
/WEB-INF/security-context.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>/home/alekss/uploads</param-value>
</init-param>
<init-param>
<description>Maximum size of stored in memory file</description>
<param-name>thresholdSize</param-name>
<param-value>10240000</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring security filter -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
</web-app>
和.xhtml文件代码如下
<p:fileUpload id="fileUp" fileUploadListener="#{businessInformationBean.file}" mode="commons" />
请给我意见缺什么..its很多迷惑我的... 在此先感谢。
感谢DAVO :) 是其工作的感谢答复:) 让我分享我的整个情况......我有一种形式... [名/ idProfImage/ 地址/ 图像] 为了这个,我想要两个文件上传控制器.... 作为该文件的上传控制其上传时上传按钮,单击 我是新的primefaces :)所以从你这什么建议吗? – Minesh
我只想在save()方法中获取图像obj,以便我可以继续使用其他表单数据以用于保存目的.... – Minesh
在您的handleFileUpload方法中,可以设置控制器/ bean变量file = event.getFile );然后在你的保存方法中,你可以得到文件变量来获得流,file.getInputStream() – DavoCoder