0
votes

I'm using Tomahawk library for the file upload. However, the backing bean's method is never called when I click on h:commandButton to submit the form.

Bellow is the code sequence that should do the job, and it is a part of user_profile.xhtml page(which is stored in the root of WebContent folder; the application is deployed on JBoss 6.1):

<p:dialog widgetVar="avatar" hideEffect="fade" width="300" height="300"
    header="Avatar upload">
    <h:form enctype="multipart/form-data">
        <t:inputFileUpload value="#{uploadBean.uploadedFile}" id="upload" />
        <h:commandButton value="Upload" action="#{uploadBean.submit}" />
    </h:form>
</p:dialog>

The link that provides access to the page is http://localhost:8080/user/20, because there is url-mapping set in pretty-config.xml file, which looks like:

<url-mapping id="user_profile">
    <pattern value="/user/#{id}"></pattern>
    <view-id value="/user_profile.jsf"></view-id>
</url-mapping>

However, when I access the page directly, by avoiding pretty-config mapping, http://localhost:8080/user_profile.jsf, upload action works fine! So, I suppose there is some conflict with pretty faces or I overlooked something.

Thanks in advance!

The beginning of 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" id="YAS" version="3.0">
  <display-name>YouAndShoe</display-name>

  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
 </context-param>

  <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>

  <filter>
    <filter-name>Pretty Filter</filter-name>
    <filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>Pretty Filter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ERROR</dispatcher>
  </filter-mapping>
...
1
In what order are the filters declared in web.xml? I've never used them together, but it would make sense if the PrettyFaces one runs before the Tomahawk one. - BalusC
@BalusC: PrettyFaces filter was running before the Thomahawk one, but I changed that, and it still doesn't work. I uploaded one part of web.xml content. - CyberMJ
But it shows the Tomahawk filter before the PrettyFaces filter. Anyway, I think it's better to report a bug to PrettyFaces guys at their own site. - BalusC
@BalusC: Yes, it shows the Tomahawk before Pretty, because I changed the content of web.xml I when read your first comment. Anyways, tnx, I will report a bug to their site. - CyberMJ

1 Answers

2
votes

The Tomahawk filter was not registered properly (there were no dispatcher(s) defined). This is how it should be done:

<?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" id="YAS" version="3.0">
  <display-name>YouAndShoe</display-name>

  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
 </context-param>



  <filter>
    <filter-name>Pretty Filter</filter-name>
    <filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>Pretty Filter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ERROR</dispatcher>
  </filter-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>
  <dispatcher>FORWARD</dispatcher>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>ERROR</dispatcher>
</filter-mapping>
<filter-mapping>
  <filter-name>MyFacesExtensionsFilter</filter-name>
  <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
  <dispatcher>FORWARD</dispatcher>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>ERROR</dispatcher>
</filter-mapping> 
...

This solved the problem.