Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7806767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:38:17+00:00 2026-06-02T02:38:17+00:00

I read many pages but, i’m sure, I did some errors somewhere and I

  • 0

I read many pages but, i’m sure, I did some errors somewhere and I can’t do the upload of a file simply as It should be.

First, I’m developing using JSF2.0, Primefaces 3.2 and JPA2 on Glassfish 3.1 with Netbeans 7 and JDK 1.7.

The next thing that I must say is that I’m tringg to insert this code into an interface that will be extended from many others classes and that should store the files in many folders on filesystem!
So now I will report what I wrote and, please, tell me where is the problem!

This is the code into web.xml:

<filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
    <init-param>
        <param-name>uploadDirectory</param-name>
        <param-value>D:/Cyborg/</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>  

The page that contains the p:uploadFile contains also many other form’s fields and I will copy only what I think is of your interest:

...
<h:form method="POST">
    ...
    <h:outputLabel for="uploadFile" value="#{bundle.LabelUploadFile}" />
    <p:fileUpload value="#{progettiController.uploadFile}" mode="simple" />
    ...
    <h:commandLink action="#{progettiController.create}" value="#{bundle.SaveLink}" />
    ...

this is the code into the interface called AbstractController:

protected UploadedFile uploadFile;

public void setUploadFile(UploadedFile uploadFile) {
    this.uploadFile=uploadFile;
}

public UploadedFile getUploadFile() {
    return uploadFile;
}

and finally the method Create into ProgettiController:

public String create() {
    try {
        getFacade().create(current);
        System.out.println("Message: ProgettiController: Create: new row created successfully!");

        try {
            current=getFacade().findLast();
            String ext=uploadFile.getFileName();
            System.out.println("Message: ProgettiController: Create: FileName="+ext);

            ext=ext.substring(ext.lastIndexOf("."),ext.length());
            System.out.println("Messaggio: ProgettiController: ext="+ext);

            current.setNomeFile(ext.substring(0,ext.lastIndexOf(".")));
            current.setTipoFile(ext.substring(ext.lastIndexOf(".")+1,ext.length()));
            getFacade().edit(current);
            ext=urlFilesystem+current.getId()+ext.substring(ext.lastIndexOf(".")+1,ext.length());
            System.out.println("Message: ProgettiController: Create: posizione e nome del file="+ext);

            File oldFile= (File)uploadFile;
            File newFile= new File(ext);
            oldFile.renameTo(newFile);
        } catch (Exception e) {
            System.out.println("Messaggio: ProgettiController: Create: errore nel try legato al upload="+e.getMessage());
            e.printStackTrace();
        }

        JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("ProgettiCreated"));
        recreateModel();
        System.out.println("Messaggio: ProgettiController: create try");
        return url+"List?faces-redirect=true";
    } catch (Exception e) {
        JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
        System.out.println("Messaggio: ProgettiController: create catch="+e.getMessage());
        e.printStackTrace();
        return url+"List?faces-redirect=true";
    }
}

If I try this code the problem is that when the page call the method returns null into uploadFile, if I add the “enctype=”multipart/form-data”” into h:form tag the application didn’t call the method!
Can someone help me? Thanks a lot!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:38:19+00:00Added an answer on June 2, 2026 at 2:38 am

    if I add the “enctype=”multipart/form-data”” into h:form tag the application didn’t call the method!

    That would mean that the PrimeFaces file upload filter wasn’t able to do its job properly. It is responsible for parsing a multipart/form-data request and providing the parsed data further to JSF in an understandable form (until the upcoming JSF 2.2 version, JSF does by default not support multipart/form-data requests).

    That can have at least the following main reasons:

    • The <servlet-name> in the <filter-mapping> is incorrect. You need to make sure that it’s exactly the same <servlet-name> of the <servlet> configuration of the FacesServlet in the same web.xml.

    • The Commons IO and FileUpload JARs are not in the webapp’s runtime classpath. I don’t use Netbeans, so I can’t go in detail, but whatever way you use to include the JARs in the webapp, you need to make absolutely sure that they end up in /WEB-INF/lib folder of the deployed webapp. You can verify that by checking the deploy in the server. In Eclipse, that can among others be achieved by just dropping those JARs straight in exactly that folder of the web project.

    • You happen to have another Filter in your web application which does roughly the same job as the PrimeFaces file upload filter and is executed before the PrimeFaces file upload filter. For example, the MyFaces ExtensionsFilter which is bundled in Tomahawk. The request body can namely be parsed only once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I (like many others) followed the webview tutorial, but I can't get pages to
I have read many questions about Android, J2ME and RecordStore , but I still
I have read many questions about the facebook login but until not I didnt
I've read many different articles/threads on this, but have yet to determine the best
I have given some thought on how to calculate how many users I can
My app is a digital magazine consisting of many pages. Some pages have video
I completed the StockWatcher basic gwt tutorial, and read several pages of documentation but
I've read many answers to similar questions, but still didn't get to the answer
I already read many article about this issue in here, SO. I just want
I have read many fine algorithms for identifying the most significant bit for 32-

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.