Conflict between use of hx:fileupload and tomahawk tree2 component in the application

340 views Asked by At

I'm using hx:fileupload component which allows the user to open local file system and browse to the file. In the same application I have used tomahawk tree2 component to display hierarchical directory structure.

Earlier to adding tree2 component, fileupload was working perfect but when I added the filter tag corresponding to tomahawk tree2 in web.xml file, getFileupload1().getFilename() method of hx:fileupload component (where getFileupload1() is getter method of hx:fileupload component) return null exception.

Filter tag code:

<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-mapping>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <url-pattern>*.jsf</url-pattern>
</filter-mapping>

If i remove filter tag from web.xml file, fileupload component resumes to work properly but Tree2 component won't work.

Please help to make both components work together in the application.

Thank you

I have done the following updations:

  1. Implemented ExtensionsFilter filter servlet by removing if (ServletFileUpload.isMultipartContent(httpRequest)) {} block from the original ExtensionsFilter source code file.

updated web.xml code

<filter>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <filter-class>pagecode.ExtensionsFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter-mapping>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <url-pattern>*.jsf</url-pattern>
</filter-mapping>

Please help. Thanks.

1

There are 1 answers

5
BalusC On BEST ANSWER

The ExtensionsFilter also automatically parses multipart/form-data requests as part of its job for Tomahawk's <t:inputFileUpload>. This is not disableable by configuration.

You have basically 2 options:

  1. Copy the source code of ExtensionsFilter under the same license and remove the whole if (ServletFileUpload.isMultipartContent(httpRequest)) {} block (lines 347-350) so that it doesn't parse multipart/form-data requests anymore and use this filter instead.

  2. Replace <hx:fileUpload> by <t:inputFileUpload>.