0

I Developed a web application on my laptop (using JDK 1.8, primefaces 5.0 and glassfish 4.1) and deployed on a server (which has JDK 1.7 and glassfish 3.1 installed) the primefaces fileupload works on my laptop but gives a nullpointer exception when deployed on the server. this is my page:

<p:fileUpload update="pimage" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" 
value="#{newUserBean.file}" required="true"requiredMessage="Select a picture to upload"  mode="simple"/>
<h:commandButton style="width: 150px;height: 40px" value="Submit" actionListener="#{newUserBean.save()}">
 <f:ajax execute="@all" render="@form"/>
</h:commandButton>

this is my save method:

public void save() {
        String url = null;
        try {
            //String fullname = getSurname() + " "+ getOtherNames();
            Map<String, String> map = new NewUserEntity().createUser(1, getUserName(), getSurname(), getOtherNames(), getJob(), getUserGroup(), getPassword(), getEmail(),
                    Integer.parseInt(getStaffID()), getDateOfBirth(), getAddress(), getPhoneNo(),
                    getDepartment(), getAcademicQualification(), getGrade(), getProfQuailification(), getCourse(), file.getInputstream(), getSex(), Integer.parseInt(getExtension()));

            if (map.get("responseMessage").equalsIgnoreCase("User Added Successfully")) {
                url = "addUser.xhtml?faces-redirect=true";
            } else {
                url = "";
            }
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "", map.get("responseMessage"));
            FacesContext.getCurrentInstance().addMessage(null, msg);
        } catch (Exception e) {
            e.printStackTrace();
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_FATAL, "Error", e.toString());
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
        //return url;
    }

and this is my a portion of my web.xml file

<context-param>
        <param-name>primefaces.UPLOADER</param-name>
        <param-value>commons</param-value>
    </context-param>
    
    <error-page>
        <exception-type>
            javax.faces.application.ViewExpiredException
        </exception-type>
        <location>/Web Pages/Login.xhtml</location>
    </error-page>
    
    <filter>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
        <init-param>
            <param-name>thresholdSize</param-name>
            <param-value>51200</param-value>
        </init-param>
        <init-param>
            <param-name>uploadDirectory</param-name>
            <param-value>c:/tmp</param-value>
        </init-param>
    </filter>
    
    <filter-mapping>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
  • The primefaces file upload is mapped to "private UploadedFile file" in the backing bean which upload the picture to the database using file.getInputstream() in the save method called by the h:commandButton – Okwuokei Chika Anthony Feb 04 '16 at 11:43
  • 1
    GF4 is JSF 2.2 and GF3.1 is JSF 2.1. This is the cause of your problem. See duplicate for required additional configuration when you're not on JSF 2.2. – BalusC Feb 04 '16 at 11:44
  • Thanks BaluC. I have tried all your suggestions on the duplicate question but its not just working. what else can i do to make it work? – Okwuokei Chika Anthony Feb 04 '16 at 15:35
  • Edit your question to include debug detail (at bottom you can find instructions, just tell which abnormalities you observed). Perhaps this is a new cause, then I will of course reopen the question. – BalusC Feb 04 '16 at 15:42
  • I added the commons file upload and commons io to the system classpath, i also put the file upload filter mapping before the mapping of a servelet that uses the getParameter() method. I also added REQUESTFORWARD to the filter mapping. but its not working. – Okwuokei Chika Anthony Feb 04 '16 at 16:17
  • Did you set context param `primefaces.UPLOADER` to `commons` just to be sure? Anyway, you still haven't told debug detail. What's odd in HTTP traffic and decode method? – BalusC Feb 04 '16 at 16:19
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/102615/discussion-between-okwuokei-chika-anthony-and-balusc). – Okwuokei Chika Anthony Feb 04 '16 at 16:35

0 Answers0