I did as BalusC's step by step tutorial: JSF 2.0 File upload
But I then found that the UploadedFile is null when I clicked the commandButton.
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>web</display-name>
<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>/faces/*</url-pattern>
</servlet-mapping>
<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>
.....some <context-param> generated automatically
</web-app>
webpage:
<h:form id="register_doctor_form" encrypt="multipart/form-data">
<table>
<tr>
<td><h:outputText value=" Image"></h:outputText></td>
<td>
<t:inputFileUpload value="#{DoctorRegisterBean.image}"></t:inputFileUpload>
</td>
</tr>
<tr>
<td><h:outputText id="submit_message" value="#{DoctorRegisterBean.message_submit}"></h:outputText></td>
<td id="last_td">
<h:commandButton class="button" value="Create Doctor" action="#{DoctorRegisterBean.registerDoctor}">
<f:ajax execute="register_doctor_form" render="submit_message"></f:ajax>
</h:commandButton>
</td>
</tr>
</table>
</h:form>
I also read this post: UploadedFile is null when submit jsf upload request with Tomahawk, but my form is not nested.
ManagedBean:
public class DoctorRegisterBean implements Serializable{
private UploadedFile image;
public void registerDoctor() {
byte[] imageBytes = image.getBytes();
Blob blob = new SerialBlob(imageBytes);
}
}
The image here is NULL. So what's wrong with this code?
I run this project using .war file under tomcat, and the error message is given when I click on the commandButton, here is the error message:
javax.faces.el.EvaluationException: javax.el.ELException: /admin_doctorregister.xhtml at line 124 and column 115 action="#{DoctorRegisterBean.registerDoctor}": java.lang.NullPointerException
at javax.faces.component._MethodExpressionToMethodBinding.invoke(_MethodExpressionToMethodBinding.java:96)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:100)
at javax.faces.component.UICommand.broadcast(UICommand.java:120)
at javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:937)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:271)
at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1249)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:675)
at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:34)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:357)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.el.ELException: /admin_doctorregister.xhtml at line 124 and column 115 action="#{DoctorRegisterBean.registerDoctor}": java.lang.NullPointerException
at org.apache.myfaces.view.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:95)
at javax.faces.component._MethodExpressionToMethodBinding.invoke(_MethodExpressionToMethodBinding.java:88)
... 29 more
Caused by: java.lang.NullPointerException
at edu.upenn.cis.rtg.ohc.web.DoctorRegisterBean.registerDoctor(DoctorRegisterBean.java:134)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at org.apache.myfaces.view.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:83)
... 30 more
<h:form id="register_doctor_form" encrypt="multipart/form-data">
is the problem it should be
<h:form id="register_doctor_form" enctype="multipart/form-data">
Related
I found similar problem here but the solution for that didn't resolve my problem.
The link for the similar problem is here enter link description here.
Well about my problem, progressbar won't update when I click on the radio button.
my fxml file for that scene is here
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
minWidth="-Infinity" prefHeight="468.0" prefWidth="972.0" style="-fx-
background-color: #02b496;" xmlns="http://javafx.com/javafx/9.0.1"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="Controllers.RegisterController">
<children>
<ImageView fitHeight="497.0" fitWidth="972.0" opacity="0.68" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#LogInPic.jpg" />
</image>
</ImageView>
<AnchorPane id="registration" fx:id="registration" layoutX="544.0" layoutY="49.0" opacity="0.91" prefHeight="357.0" prefWidth="359.0" style="-fx-background-color: orange;">
<children>
<Text layoutX="94.0" layoutY="44.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Sign Up" textAlignment="CENTER" wrappingWidth="133.5869140625">
<font>
<Font size="18.0" />
</font>
</Text>
<Text layoutX="30.0" layoutY="107.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Welcome to register pane " wrappingWidth="189.13671875">
<font>
<Font size="14.0" />
</font>
</Text>
<RadioButton fx:id="menadzer" layoutX="30.0" layoutY="195.0" mnemonicParsing="false" onAction="#handleMenadzerBtn" text="Manager" />
<RadioButton fx:id="kupac" layoutX="161.0" layoutY="195.0" mnemonicParsing="false" onAction="#handleKupacBtn" text="Customer" />
<Text layoutX="30.0" layoutY="146.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Before you start registration choose one of the following" wrappingWidth="226.283203125">
<font>
<Font size="14.0" />
</font>
</Text>
<Text layoutX="30.0" layoutY="257.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Registartion procces completion">
<font>
<Font size="14.0" />
</font>
</Text>
<Button layoutX="246.0" layoutY="270.0" mnemonicParsing="false" onAction="#handleBackBtn" prefHeight="17.0" prefWidth="92.0" style="-fx-background-color: #df8020;" text="Back">
<font>
<Font size="15.0" />
</font>
</Button>
<ProgressBar fx:id="pb" layoutX="30.0" layoutY="273.0"
opacity="0.57" prefHeight="24.0" prefWidth="200.0" progress="0.0" />
</children>
</AnchorPane>
</children>
</AnchorPane>
My controller class
In this class i am setting progress to my bar and its trowing me null pointer exception, i really cant find where the problem is so i need you help.
public class RegisterController implements Initializable {
#FXML
private ProgressBar pb;
#FXML
private void handleMenadzerBtn(ActionEvent event) throws IOException {
pb.setProgress(0.1);
long mTime = System.currentTimeMillis();
long end = mTime + 2000;
while (mTime < end) {
mTime = System.currentTimeMillis();
}
Parent root = FXMLLoader.load(getClass().getResource("/View/Home.fxml"));
Scene scene = new Scene(root);
Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
window.setTitle("JavaFX and Maven");
window.setScene(scene);
window.show();
}
/**
* Initializes the controller class.
* #param url
* #param rb
*/
#Override
public void initialize(URL url, ResourceBundle rb) {
}
}
The error code i am gettig is here :
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.ToggleButton.fire(ToggleButton.java:256)
at javafx.scene.control.RadioButton.fire(RadioButton.java:113)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:380)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:294)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:416)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:415)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
... 49 more
Caused by: java.lang.NullPointerException
at Controllers.RegisterController.handleMenadzerBtn(RegisterController.java:41)
... 59 more
Feb 13, 2018 4:19:42 PM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 9.0.1 by JavaFX
runtime of version 8.0.101
So if someone could help, i would be thankful, if you need some more material just ask.
You are facing the error at this line
pb.setProgress(0.1);
Because your ProgressBar is null. You have to initialize ProgressBar before using the object of ProgressBar.
I cannot make the fileUpload option working. I keep having the message file is null.
Could you tell me how to fix this ?
here is my xhtml:
<h:form enctype="multipart/form-data">
<p:fileUpload mode="simple" id="recupereFile" value="#{FileUploadView.uploadedFile}" />
<p:commandButton value="Upload" action="#{FileUploadView.upload}" ajax="false" />
</h:form>
here is my java:
#ManagedBean(name="FileUploadView")
public class FileUploadView {
private UploadedFile file;
public UploadedFile getFile() {
System.out.println(file);
return file;
}
public void setFile(UploadedFile file) {
this.file = file;
}
public void upload() {
UploadedFile file = getFile();
System.out.println("hello");
System.out.println(file);
if(file != null) {
FacesMessage message = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
System.out.println(message);
}
}
}
file is always null !
my web.xml
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>
org.primefaces.webapp.filter.FileUploadFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
I have these jars:
commons-fileupload-1.3.1.jar
commons-io_2.5.jar
Thansk for your help.
We had a similar issue a few month ago here. The colleague who did this left our company, so I can't ask him. Anyway this is how the relevant parts of my web.xml look like.
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<url-pattern>*.jsf</url-pattern>
</filter-mapping>
Also we have this context-param:
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>auto</param-value>
</context-param>
The value attribute of p:fileUpload should correspond to the name of the UploadedFile in the bean.
It should work if you replace FileUploadView.uploadedFile with FileUploadView.file in the p:fileUpload:
<p:fileUpload mode="simple" id="recupereFile" value="#{FileUploadView.file}" />
I'm developing a web application with PrimeFaces 4.0.RC1 and i have problem with file upload,
exactly with the fileUploadListener; this listener doesn't invoke the method "handleFileUpload".
When i try to invoke this method with commandButton: the action in the commandButton work fine;
this is a pert of my web.xml:
<!-- Filter for the JSF uploder -->
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>commons</param-value>
</context-param>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>facesServlet</servlet-name>
</filter-mapping>
this my xhtml page:
<h:form enctype="multipart/form-data">
<p:growl id="kpiUploadNote" showDetail="true" sticky="true" />
<!-- Test with advanced fileUpload -->
<p:fileUpload
fileUploadListener="#{fileUploadController.handleFileUpload}"
mode="advanced" dragDropSupport="false" sizeLimit="100000"
update="kpiUploadNote" fileLimit="3" allowTypes="/(\.|\/)(csv|xlsx)$/" />
<!-- Test with commandButton to test the bean -->
<p:commandButton action="#{fileUploadController.handleFileUpload}"
update="kpiUploadNote" ajax="false" />
</h:form>
this my ManagedBean:
#Scope
#ManagedBean(name = "fileUploadController")
public class FileUploadController {
public void handleFileUpload(FileUploadEvent event) {
System.out.println("calling file upload...");
FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void handleFileUpload() {
FacesMessage msg = new FacesMessage("Succesful", " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
This my first Question in stack overflow and i hope you help me :),
I've been working on this for a while and I managed to make this component work perfectly like this:
<h:form enctype="multipart/form-data">
<p:panelGrid columns="2">
<p:outputLabel value="Nombre:" for="nombre"/>
<p:inputText id="nombre" value="# {controladorProducto.producto.nombre}"/>
<p:outputLabel value="Descripción" for="descripcion"/>
<p:inputText id="descripcion" value="#{controladorProducto.producto.descripcion}"/>
<p:outputLabel value="Precio" for="precio"/>
<p:inputText id="precio" value="#{controladorProducto.producto.precio}"/>
<p:fileUpload id="fileuploader" value="#{controladorProducto.uploadedFile}"
mode="simple" />
<p:commandButton id="boton_cargar" value="Cargar" actionListener="#{controladorProducto.handleProductImageUpload}"
update="fotoProducto" ajax="true"/>
<p:outputLabel value="Imagen:" for="fotoProducto"/>
<p:graphicImage id="fotoProducto" value="#{controladorProducto.producto.imageToShow}"/>
<p:commandButton value="Insertar" action="#{controladorProducto.insertarProducto()}"/>
</p:panelGrid>
</h:form>
So as soon as I add any UI Component (you know, templates) it stops working. Here is the form with the template codes:
<ui:define name="top">
<h1>Buscador Clientes</h1>
<h:form id="form_growl">
<p:growl showDetail="false" />
</h:form>
</ui:define>
<ui:define name="left">
<h:form>
<p:menubar>
<p:menuitem value="Clientes" action="#{controladorCliente.buscarTodosClientes}" />
<p:separator/>
<p:menuitem value="Productos" action="#{controladorProducto.buscarTodosProductos}"/>
<p:separator/>
<p:menuitem value="Pedidos" url="#"/>
</p:menubar>
</h:form>
</ui:define>
<ui:define name ="content">
<h:form enctype="multipart/form-data">
<p:panelGrid columns="2">
<p:outputLabel value="Nombre:" for="nombre"/>
<p:inputText id="nombre" value="#{controladorProducto.producto.nombre}"/>
<p:outputLabel value="Descripción" for="descripcion"/>
<p:inputText id="descripcion" value="#{controladorProducto.producto.descripcion}"/>
<p:outputLabel value="Precio" for="precio"/>
<p:inputText id="precio" value="#{controladorProducto.producto.precio}"/>
<p:fileUpload id="fileuploader" value="#{controladorProducto.uploadedFile}"
mode="simple" />
<p:commandButton id="boton_cargar" value="Cargar" actionListener="#{controladorProducto.handleProductImageUpload}"
update="fotoProducto" ajax="true"/>
<p:outputLabel value="Imagen:" for="fotoProducto"/>
<p:graphicImage id="fotoProducto" value="#{controladorProducto.producto.imageToShow}"/>
<p:commandButton value="Insertar" action="#{controladorProducto.insertarProducto()}"/>
</p:panelGrid>
</h:form>
</ui:define>
</ui:composition>
Is there any problem, I've used the same template in other places of my project and it worked fine, its just here where it crashes. I get a NullPointerException and when i Debug it It didnt even call the bean.
At this point I´ve been looking around the Internet and I've not found anything.
Does anybody has any idea of why it doesnt works?
By the way, Im using NetBeans 7.3, GlassFish 3.1.2, Primefaces 3.5, JSF 2.1....
I hope someone answers me, I'd appreciate any help or clue on this.
This is the Error trace I get:
SEVERE: Se ha recibido 'java.lang.NullPointerException' al invocar la escucha de acción '#{controladorProducto.handleProductImageUpload}' para el componente 'boton_cargar'
SEVERE: java.lang.NullPointerException
at Controlador.ControladorProducto.handleProductImageUpload(ControladorProducto.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.el.parser.AstValue.invoke(AstValue.java:254)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:302)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
SEVERE: JSF1073: se ha interceptado javax.faces.event.AbortProcessingException durante el procesamiento de INVOKE_APPLICATION 5 : UIComponent-ClientId=j_idt22:boton_cargar, Mensaje=java.lang.NullPointerException
SEVERE: java.lang.NullPointerException
javax.faces.event.AbortProcessingException: java.lang.NullPointerException
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:182)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at Controlador.ControladorProducto.handleProductImageUpload(ControladorProducto.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.el.parser.AstValue.invoke(AstValue.java:254)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:302)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)
... 38 more
I'm trying to implement a page with primefaces fileUpload but my handleUpload function isn't triggered.
My xhtml:
<h:form enctype="multipart/form-data">
<p:panel id="uploadFormPanel" header="File upload">
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="#{criteriaTranslation.questionaireFile}:" />
<p:fileUpload update="uploadMessages"
fileUploadListener="#{critereCSVImporter.handleFileUpload}"
mode="advanced"
allowTypes="/(\.|\/)(csv)$/"/>
</h:panelGrid>
<p:growl id="uploadMessages" showDetail="true"/>
</p:panel>
</h:form>
My backing bean:
#ManagedBean
#ViewScoped
public class CritereCSVImporter {
#Inject
private CriteriaBL criteriaBL;
private String OCRMODE;
public void handleFileUpload(FileUploadEvent event) {
System.out.println("handle");
InputStream inputStream = event.getFile().getInputstream();
}
My web.xml:
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>
org.primefaces.webapp.filter.FileUploadFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
Am I missing something?
Place commons-fileupload and commons-io jars in your lib folder
Apache Commons FileUpload
Apache Commons IO