0

I was trying to create a file uploader using JSF. I referred to several articles on various forums and SO but nothing worked, so it felt, may be I have some other case and posted it. I am using enctype in form, I have both commons-IO and commons-fileupload and I have added proper filters in web.xml. But it still doesn't work and throws NullPointerException.

<h:form id="expenseForm" enctype="multipart/form-data"">
    <table class="table table-condensed table-bordered table-hover table-striped">
        <tr>
           <td><h:outputText value="#{BHMaintenanceController.getSelectedLanguageLabel('Reason For Expense')}"/></td>
           <td><p:inputText value="#{BHMaintenanceController.newExpense.reason}"/></td>
        </tr>
        <tr>
           <td><h:outputText value="#{BHMaintenanceController.getSelectedLanguageLabel('Total Expense')}"/></td>
           <td><p:inputText value="#{BHMaintenanceController.newExpense.expense}"/></td>
        </tr>
        <tr>
           <td><h:outputText value="#{BHMaintenanceController.getSelectedLanguageLabel('Upload Receipt')}"/></td>
           <td><p:fileUpload value="#{BHMaintenanceController.expense_receipt}" mode="simple" skinSimple="true"/></td>
        </tr>
    </table>
    <p:commandButton value="#{BHMaintenanceController.getSelectedLanguageLabel('File Expense')}" ajax="false" action="#{BHMaintenanceController.fileExpense()}"></p:commandButton>
</h:form>

As you can see, I have added enctype in form correctly. I have also added commons-io-2.4 and commons-fileupload-1.3.1. I am using primefaces 5.1 and JSF 2.0.

My web.xml

<display-name>Panzer</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>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
</context-param>
<context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>start</param-value>
</context-param>

<context-param>
    <param-name>primefaces.UPLOADER</param-name>
    <param-value>auto|native|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>Faces Servlet</servlet-name>
</filter-mapping>

Is there some version problem, or am I doing something wrong?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Ayush choubey
  • 606
  • 6
  • 23
  • I am not pretty sure about but none of these `auto|native|commons` worked for me until now, when they are explicitly mentioned. There might be some problems in my application itself but I cannot see them. – Tiny Mar 30 '15 at 15:07
  • Can you suggest some kind of trouble shooting guide, to figure out the problem, I tried using chrome dev tools(F12 and then network) and it showed that form is trying to upload the file.using filename=something. I don't really get what's wrong. Anyways is there any troubleshoot guide so that i can find where my problem is. Thanks :) – Ayush choubey Mar 31 '15 at 01:40

0 Answers0