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 8326637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:49:36+00:00 2026-06-09T00:49:36+00:00

I have the following page using JSF to upload a .pdf file to a

  • 0

I have the following page using JSF to upload a .pdf file to a folder designated on the server. However, the commandButton action does not seem to be firing at all, as none of my println()s show, nor my message update. If anyone could explain the issue, it would be greatly appreciated.

XHTML page:

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:t="http://myfaces.apache.org/tomahawk"
    xmlns:f="http://java.sun.com/jsf/core" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="keywords" content="enter,your,keywords,here" />
        <meta http-equiv="description"
            content="A short description of this page." />
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />

        <link rel="stylesheet" type="text/css" href="Styles/style.css" />
        <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.7.2.min.js"></script>
    </head>
    <body>


        <h:form enctype="multipart/form-data">
            <h:outputText value="First Name: " />
            <h:inputText id="fname" size="40" value="#{userBean.firstName}" required="true"/> <br/>
            <h:outputText value="Last Name: " />
            <h:inputText id="lname" size="40" value="#{userBean.lastName}" required="true"/> <br/>
            <h:outputText value="Position Sought: "/>
            <h:inputText id="position" size="40" value="#{userBean.position}" required="true"/> <br/>
            <h:outputText value="File to upload: " />
            <t:inputFileUpload value="#{userBean.resume}" /> <br/>
            <h:commandButton value="submit" action="#{userBean.submit}" />
            <h:messages />
        </h:form>

    </body>
</html>

faces:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xi="http://www.w3.org/2001/XInclude"
 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_2_0.xsd">
 <managed-bean>
  <managed-bean-name>userProcessor</managed-bean-name>
  <managed-bean-class>com.logic.UserProcessor</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
  <managed-property>
   <property-name>ID</property-name>
   <property-class>java.lang.String</property-class>
   <value/>
  </managed-property>
  <managed-property>
   <property-name>firstName</property-name>
   <property-class>java.lang.String</property-class>
   <value/>
  </managed-property>
  <managed-property>
   <property-name>lastName</property-name>
   <property-class>java.lang.String</property-class>
   <value/>
  </managed-property>
  <managed-property>
   <property-name>password</property-name>
   <property-class>java.lang.String</property-class>
   <value/>
  </managed-property>
  <managed-property>
   <property-name>resume</property-name>
   <property-class>java.lang.String</property-class>
   <value/>
  </managed-property>
  <managed-property>
   <property-name>username</property-name>
   <property-class>java.lang.String</property-class>
   <value/>
  </managed-property>
 </managed-bean>
 <managed-bean>
  <managed-bean-name>userBean</managed-bean-name>
  <managed-bean-class>com.logic.UserBean</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
  <managed-property>
   <property-name>id</property-name>
   <property-class>java.lang.String</property-class>
   <value/>
  </managed-property>
  <managed-property>
   <property-name>username</property-name>
   <property-class>java.lang.String</property-class>
   <value/>
  </managed-property>
  <managed-property>
   <property-name>password</property-name>
   <property-class>java.lang.String</property-class>
   <value/>
  </managed-property>
  <managed-property>
   <property-name>firstName</property-name>
   <property-class>java.lang.String</property-class>
   <value/>
  </managed-property>
  <managed-property>
   <property-name>lastName</property-name>
   <property-class>java.lang.String</property-class>
   <value/>
  </managed-property>
  <managed-property>
   <property-name>position</property-name>
   <property-class>java.lang.String</property-class>
   <value/>
  </managed-property>
  <managed-property>
   <property-name>resume</property-name>
   <property-class>org.apache.myfaces.custom.fileupload.UploadedFile</property-class>
   <value/>
  </managed-property>
 </managed-bean>
 <navigation-rule>
  <from-view-id>/addUser.xhtml</from-view-id>
  <navigation-case>
   <from-outcome>failure</from-outcome>
   <to-view-id>/addUser.xhtml</to-view-id>
  </navigation-case>
  <navigation-case>
   <from-outcome>success</from-outcome>
   <to-view-id>/Home_Menu.xhtml</to-view-id>
  </navigation-case>
 </navigation-rule>
 <navigation-rule>
  <from-view-id>/Home_Menu.xhtml</from-view-id>
 </navigation-rule>
 <navigation-rule>
  <from-view-id>/login.xhtml</from-view-id>
  <navigation-case>
   <from-outcome>failure</from-outcome>
   <to-view-id>/login.xhtml</to-view-id>
  </navigation-case>
  <navigation-case>
   <from-outcome>success</from-outcome>
   <to-view-id>/Home_Menu.xhtml</to-view-id>
  </navigation-case>
 </navigation-rule>
 <navigation-rule>
  <from-view-id>/upload_resume.xhtml</from-view-id>
  <navigation-case>
   <from-action>#{userBean.submit}</from-action>
   <from-outcome>success</from-outcome>
   <to-view-id>/Home_Menu.xhtml</to-view-id>
  </navigation-case>
  <navigation-case>
   <from-action>#{userBean.submit}</from-action>
   <from-outcome>failure</from-outcome>
   <to-view-id>/upload_resume.xhtml</to-view-id>
  </navigation-case>
 </navigation-rule>
</faces-config>

and the bean.submit()

  public String submit() throws IOException {
        String fileName = FilenameUtils.getName(resume.getName());
        String contentType = resume.getContentType();
        InputStream is = resume.getInputStream();
        byte[] bytes = resume.getBytes();

        Date date = new Date();
        String ext = FilenameUtils.getExtension(fileName);
        System.out.println("File upload started");
        System.out.println("File name: " + fileName);
        System.out.println("Timestamp: " + contentType);
        System.out.println("Content type: " + date.toString());
        System.out.println("File extension: " + ext);

        // Now you can save bytes in DB (and also content type?)

        if(ext != "pdf"){
            FacesContext.getCurrentInstance().addMessage(null, 
                    new FacesMessage(String.format("File upload failed, please make sure that your file has the correct extension (.pdf)")));
            System.out.println("File upload failed: incorrect file extension.");
            return "failure";
        } else {
            writeInfoToDB();
            is.read(bytes);

            String folder = getFirstName().charAt(0) + getLastName();                           //will not work if folder does not exist
            File file = new File("C:\\Users\\MAR-PC01\\Desktop\\apache-tomcat-7.0\\uploads\\" 
                                 + folder + "\\" + fileName);
            file.createNewFile();
            FileOutputStream fos = new FileOutputStream(file);
            fos.write(bytes);

            FacesContext.getCurrentInstance().addMessage(null, 
                new FacesMessage(String.format("File '%s' of type '%s' successfully uploaded!", fileName, contentType)));

            return "success";
        }
    }
  • 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-09T00:49:37+00:00Added an answer on June 9, 2026 at 12:49 am

    This form is submitted using multipart/form-data encoding which is by default not supported by JSF. It would only work if Tomahawk’s ExtensionsFilter is properly been registered in web.xml as per its documentation. This filter is the one responsible for parsing multipart/form-data requests and converting the individual form-data parts to normal request parameters so that JSF can transparently apply request parameters (so: the submitted values and the invoked actions) the usual way.

    If the ExtensionsFilter is not been registered and/or is not able to do its job properly due to some other disturbing factor in your webapp, then the form submit will never enter the JSF postback lifecycle.

    See also:

    • JSF 2.0 File upload
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have saved an html page using the following line of code : NSURL
I'm using Spree 0.70. In my home page view, I have the following to
I have been using the following to add a dynamic link on a page
I am using following function to load the page. I have loads of links
I have the following ASP page: <asp:Content ID=Content2 ContentPlaceHolderID=ShellContent runat=server> <form runat=server id=AddNewNoteForm method=post>
I'm using JSF 2.0 with GlassFish 3.0. I have the following Managed Bean: @ManagedBean
I have a list using basic HTML in my JSF 2.0 page, like the
I have downloaded the following page using wget and saved it in f.html http://www.ebay.com/sch/i.html?_nkw=gruen&_in_kw=1&_ex_kw=sara+quartz+embassy+bob+robert+elephants+adidas&_sacat=See-All-Categories&_okw=gruen&_oexkw=sara+quartz+embassy+bob+robert+elephants+adidas&_adv=1&_udlo=&_udhi=&_LH_Time=1&_ftrt=903&_ftrv=24&_sabdlo=&_sabdhi=&_samilow=&_samihi=&_sadis=200&_fpos=Zip+code&_fsct=&LH_SALE_CURRENCY=0&_sop=12&_dmd=1&_ipg=50
I'm using JSF 2.0 and Glassfish 3.1 and have the following problem: I've got
I currently have the following JavaScript/jQuery script that gets an external html page using

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.