Я создаю веб-приложение, которое загружает файлы, и пытаюсь добавить функции CDI, требующие использования файла beans.xml. Проблема в том, что когда я добавляю файл beans.xml в веб-приложение, он прерывает ранее функциональную загрузку входного файла даже до того, как я переключаюсь на какие-либо функции, требующие beans.xml. Почему даже наличие файла beans.xml нарушает эту функцию?
Среда и зависимости:
JDK 1.7.0_45
Netbeans IDE 7.4, исправление 2
Windows 7 версии 6.1, работающая на платформе x86
javaee-web-api-6.0
primefaces-3.5
tomahawk- 1.1.14
Сервер GlassFish 4.0
Вот код, если это поможет:
beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_1_0.xsd">
</beans>
веб.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
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<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<title>Input File Test</title>
<c:set value="${facesContext.externalContext.requestContextPath}" var="path" scope="view"/>
<link href="${path}/css/default.css" rel="stylesheet" type="text/css"/>
</h:head>
<h:body>
<div id="main">
<h:form enctype="multipart/form-data">
<p:panel header="Submit Object Relational Model">
<h:panelGrid columns="2" >
<t:inputFileUpload id="file" name="path" value="#{fileUploadController.file}"/>
<f:facet name="footer">
<h:commandButton value="Submit" action="#{fileUploadController.upload()}"/>
</f:facet>
</h:panelGrid>
<p:messages showDetail="true"/>
</p:panel>
</h:form>
</div>
</h:body>
</html>
0.xsd" >
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG-FILES</param-name>
<param-value>WEB-INF/faces-config.xml</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
<filter>
<filter-name>MyFacesExtensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<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>*.jsf</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>login.jsf</welcome-file>
</welcome-file-list>
<error-page>
<error-code>401</error-code>
<location>/WEB-INF/errorpages/unauthorized.xhtml</location>
</error-page>
</web-app>
Веб-страница (login.xhtml)
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<title>Input File Test</title>
<c:set value="${facesContext.externalContext.requestContextPath}" var="path" scope="view"/>
<link href="${path}/css/default.css" rel="stylesheet" type="text/css"/>
</h:head>
<h:body>
<div id="main">
<h:form enctype="multipart/form-data">
<p:panel header="Submit Object Relational Model">
<h:panelGrid columns="2" >
<t:inputFileUpload id="file" name="path" value="#{fileUploadController.file}"/>
<f:facet name="footer">
<h:commandButton value="Submit" action="#{fileUploadController.upload()}"/>
</f:facet>
</h:panelGrid>
<p:messages showDetail="true"/>
</p:panel>
</h:form>
</div>
</h:body>
</html>
Бин (FileUploadController.java)
import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.apache.myfaces.custom.fileupload.UploadedFile;
@SessionScoped
@ManagedBean(name = "fileUploadController")
public class FileUploadController implements Serializable {
private UploadedFile file;
public UploadedFile getFile() {
return file;
}
public void setFile(UploadedFile file) {
this.file = file;
}
public void upload() {
if(file != null) {
FacesMessage msg = new FacesMessage("Succesful! ", file.getName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
else {
FacesMessage msg = new FacesMessage("Failure to upload.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
}
лица-config.xml
<?xml version="1.0" encoding="utf-8"?>
<faces-config version="2.0" 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-facesconfig_2_0.xsd">
</faces-config>