Estou usando richfaces + myfaces e estou com problema ao usar o rich:upload.
Qualquer idéia será bem vinda.
Meus arquivos:
web.xml
<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<description>web.xml</description>
<!-- Plugging the "Blue Sky" skin into the project -->
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>DEFAULT</param-value>
</context-param>
<!-- Making the RichFaces skin spread to standard HTML controls -->
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>disabled</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.RENDER_VIEWSTATE_ID</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.STRICT_XHTML_LINKS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.VIEWSTATE_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<description>State saving method: "client" or "server" (=
default) See JSF Specification 2.5.3</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<description>Only applicable if state saving method is "server" (=
default). Defines the amount (default = 20) of the latest views are
stored in session.</description>
<param-name>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</param-name>
<param-value>20</param-value>
</context-param>
<context-param>
<description>Only applicable if state saving method is "server" (=
default). If true (default) the state will be serialized to a byte
stream before it is written to the session. If false the state will
not be serialized to a byte stream.</description>
<param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>Only applicable if state saving method is "server" (=
default) and if org.apache.myfaces.SERIALIZE_STATE_IN_SESSION is true
(= default) If true (default) the serialized state will be compressed
before it is written to the session. If false the state will not be
compressed.</description>
<param-name>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>This parameter tells MyFaces if javascript code
should be allowed in the rendered HTML output. If javascript is
allowed, command_link anchors will have javascript code that submits
the corresponding form. If javascript is not allowed, the state
saving info and nested parameters will be added as url parameters.
Default: "true"</description>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<description>If true, rendered HTML code will be formatted, so that
it is "human readable". i.e. additional line separators and
whitespace will be written, that do not influence the HTML code.
Default: "true"</description>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>If true, a javascript function will be rendered that is
able to restore the former vertical scroll on every request.
Convenient feature if you have pages with long lists and you do not
want the browser page to always jump to the top if you trigger a link
or button action that stays on the same page. Default: "false"</description>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>Used for encrypting view state. Only relevant for
client side state saving. See MyFaces wiki/web site documentation for
instructions on how to configure an application for diffenent
encryption strengths. </description>
<param-name>org.apache.myfaces.SECRET</param-name>
<param-value>NzY1NDMyMTA=</param-value>
</context-param>
<context-param>
<description> Validate managed beans, navigation rules and ensure that
forms are not nested. </description>
<param-name>org.apache.myfaces.VALIDATE</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description> Treat readonly same as if disabled attribute was set for
select elements. </description>
<param-name>org.apache.myfaces.READONLY_AS_DISABLED_FOR_SELECTS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description> Use the defined class as the class which will be called
when a resource is added to the ExtensionFilter handling. Using
StreamingAddResource here helps with performance. If you want to add
custom components and want to use the ExtensionFilter, you need to
provide your custom implementation here. </description>
<param-name>org.apache.myfaces.ADD_RESOURCE_CLASS</param-name>
<param-value>org.apache.myfaces.renderkit.html.util.DefaultAddResource</param-value>
</context-param>
<context-param>
<description> Virtual path in the URL which triggers loading of
resources for the MyFaces extended components in the ExtensionFilter.
</description>
<param-name>org.apache.myfaces.RESOURCE_VIRTUAL_PATH</param-name>
<param-value>/faces/myFacesExtensionResource</param-value>
</context-param>
<context-param>
<description> Check if the extensions-filter has been properly
configured. </description>
<param-name>org.apache.myfaces.CHECK_EXTENSIONS_FILTER</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description> Define partial state saving as true/false.
</description>
<param-name>javax.faces.PARTIAL_STATE_SAVING_METHOD</param-name>
<param-value>false</param-value>
</context-param>
<!-- Spring Hibernate Filter -->
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*.jsf</url-pattern>
</filter-mapping>
<!-- Listener, to allow Jetty serving MyFaces apps -->
<listener>
<listener-class>
org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
<!-- Spring configuration -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<!-- Welcome files -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<filter>
<display-name>Ajax4jsf Filter</display-name>
<filter-name>ajax4jsf</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
<init-param>
<param-name>maxRequestSize</param-name>
<param-value>1000000</param-value>
</init-param>
<init-param>
<param-name>createTempFiles</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter>
<filter-name>extensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
<init-param>
<param-name>uploadMaxFileSize</param-name>
<param-value>100m</param-value>
</init-param>
<init-param>
<param-name>uploadThresholdSize</param-name>
<param-value>100k</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>ajax4jsf</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>extensionsFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<!-- Extensions Filter -->
<filter-mapping>
<filter-name>extensionsFilter</filter-name>
<url-pattern>*.jsf</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>extensionsFilter</filter-name>
<url-pattern>/faces/*</url-pattern>
</filter-mapping>
</web-app>
faces-config.xml
<?xml version='1.0' encoding='UTF-8'?>
<faces-config 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_1_2.xsd"
version="1.2">
<managed-bean>
<managed-bean-name>importacao</managed-bean-name>
<managed-bean-class>managedbean.ImportacaoBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
importacao.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<f:view>
<h:messages title="Erros" showDetail="true"/>
<h:form styleClass="cadastro">
<h:outputText value="Importação" styleClass="title"/>
<rich:panel styleClass="tabela-form">
<h:panelGrid columns="1">
<rich:fileUpload uploadData="#{importacao.itens}" addControlLabel="Adicionar Arquivo" locale="pt_BR" clearAllControlLabel="Limpar tudo"
maxFilesQuantity="1" id="upload" immediateUpload="false"
acceptedTypes="txt, csv, xls, jpg, ico" allowFlash="true" listHeight = "40px" listWidth="450px">
</rich:fileUpload>
<h:panelGroup styleClass="botaoform">
<h:commandLink value="Processar Arquivo" action="#{colaboradorImp.processar}"/>
</h:panelGroup>
</h:panelGrid>
</rich:panel>
</h:form>
</f:view>
ImportacaoBean.java
package br.com.cbss.managedbean;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import org.richfaces.event.UploadEvent;
import org.richfaces.model.UploadItem;
public class ImportacaoBean {
public List<UploadItem> itens = new ArrayList<UploadItem>();
public void upload(UploadEvent event) {
System.out.println("-----Importando------");
}
public List<UploadItem> getItens() {
return itens;
}
public void setItens(List<UploadItem> itens) {
this.itens = itens;
}
public String processar() {
FacesMessage fm = null;
if (!itens.isEmpty()) {
fm = new FacesMessage("", "Arquivo:[" + itens.get(0).getFile()
+ " Kb Importado com sucesso");
} else {
fm = new FacesMessage("", "Falha na importaçao");
}
FacesContext.getCurrentInstance().addMessage(null, fm);
return null;
}
}
Exceção
27/06/2009 02:02:57 org.apache.myfaces.config.annotation.TomcatAnnotationLifecycleProvider newInstance
INFO: Creating instance of managedbean.ImportacaoBean
27/06/2009 02:02:57 javax.faces.webapp._ErrorPageWriter handleException
SEVERE: An exception occurred
javax.faces.FacesException: Exception while decoding component : {Component-Path : [Class: org.ajax4jsf.component.AjaxViewRoot,ViewId: /importacao.jsp][Class: javax.faces.component.html.HtmlForm,Id: j_id_jsp_160709683_2][Class: org.richfaces.component.html.HtmlPanel,Id: j_id_jsp_160709683_4][Class: javax.faces.component.html.HtmlPanelGrid,Id: j_id_jsp_160709683_5][Class: org.richfaces.component.html.HtmlFileUpload,Id: upload]}
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:515)
at javax.faces.component.UIInput.decode(UIInput.java:184)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:641)
at javax.faces.component.UIInput.processDecodes(UIInput.java:114)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:637)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:637)
at javax.faces.component.UIForm.processDecodes(UIForm.java:57)
at org.ajax4jsf.component.AjaxViewRoot$1.invokeContextCallback(AjaxViewRoot.java:392)
at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:238)
at org.ajax4jsf.component.AjaxViewRoot.processDecodes(AjaxViewRoot.java:409)
at org.apache.myfaces.lifecycle.ApplyRequestValuesExecutor.execute(ApplyRequestValuesExecutor.java:32)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:103)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:76)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:148)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:100)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:365)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
at org.richfaces.renderkit.FileUploadRendererBase.doDecode(FileUploadRendererBase.java:140)
at org.ajax4jsf.renderkit.RendererBase.decode(RendererBase.java:75)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:511)
... 41 more
27/06/2009 02:02:57 org.apache.myfaces.renderkit.html.util.DefaultAddResource writeMyFacesJavascriptBeforeBodyEnd
WARNING: MyFaces special javascript could not be retrieved from request-map.