Problem when url is pretty and form enctype is multipart/form-data

Splash Forums PrettyFaces Users Problem when url is pretty and form enctype is multipart/form-data

This topic contains 8 replies, has 4 voices, and was last updated by  sergiu_oltean 6 years, 6 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #17824

    s33d
    Participant

    <h:form id=”documentFormUpload” enctype=”multipart/form-data” >

    <input type=”file” name=”uploadingFile” id=”inputFileField” />

    <h:inputText id=”city” value=”#{testFileBacking.title}” />

    <h:commandButton value=”upload” immediate=”true” action=”#{testFileBacking.uploadFileAction}”/>

    </h:form>

    When page on which this form is rendered is pretty (added configuration in pretty-faces.xml) action testFileBacking.uploadFileAction is never triggered when command button is clicked.

    This action works when:

    1. I remove enctype attripute from h:form (but file is not uploading and this isn’t right)

    2. I remove entry from pretty-faces.xml

    It might be a problem with filters ?

    #20432

    sergiu_oltean
    Participant

    I’m having the same problem. If I remove the entry from pretty-faces it works. Today I tried to use primefaces <p:upload/>. Couldn’t get it to work. I switched to tomahawks t:inputFileUpload. The action does not get called due to the problem described above.

    Maybe there’s a workaround?

    #20433

    Have you tried putting your tomohawk filter before the prettyfaces filter? You’ll need to make sure that the mappings are correct so that the filters actually invoke on the requests.

    Also, have you tried with version 3.1.1-SNAPSHOT? It may resolve these issues since there was a JSESSIONID issue.

    #20434

    sergiu_oltean
    Participant

    Hi Lincoln, tomahawk is first.

    <filter>

    <filter-name>extensionsFilter</filter-name>

    <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>

    <init-param>

    <param-name>uploadMaxFileSize</param-name>

    <param-value>100m</param-value>

    </init-param>

    <init-param>

    <param-name>uploadThresholdSize</param-name>

    <param-value>100k</param-value>

    </init-param>

    <init-param>

    <param-name>uploadRepositoryPath</param-name>

    <param-value>/temp</param-value>

    </init-param>

    </filter>

    <filter-mapping>

    <filter-name>extensionsFilter</filter-name>

    <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>

    </filter-mapping>

    <filter-mapping>

    <filter-name>extensionsFilter</filter-name>

    <url-pattern>*.jsf</url-pattern>

    </filter-mapping>

    <context-param>

    <param-name>facelets.LIBRARIES</param-name>

    <param-value>/WEB-INF/tomahawk.taglib.xml</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>

    I also tried 3.1.1 snapshot but doesn’t seems to work.

    I also tried the filters from tuckey…the same behaviour.

    When the url is rewriten the actions inside a <h:form enctype=”multipart/form-data” > does not get called.

    #20435

    Could you try to modify your <filter-mapping> this way:

    <filter-mapping>
    <filter-name>extensionsFilter</filter-name>
    <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ERROR</dispatcher>
    </filter-mapping>

    And I think placing the PrettyFilter before the ExtensionsFilter in web.xml should be correct. I’m using <t:inputFileUpload> without problems in two projects. So this should definitively work.

    #20436

    sergiu_oltean
    Participant

    Hi this is my web.xml file. As you can see I’m using spring security.

    <?xml version=”1.0″ encoding=”UTF-8″?>

    <web-app xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;

    xmlns=”http://java.sun.com/xml/ns/javaee&#8221; xmlns:web=”http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&#8221;

    xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee

    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd

    id=”springsecurity” version=”2.5″>

    <listener>

    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>

    </listener>

    <context-param>

    <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>extensionsFilter</filter-name>

    <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>

    <init-param>

    <param-name>uploadMaxFileSize</param-name>

    <param-value>100m</param-value>

    </init-param>

    <init-param>

    <param-name>uploadThresholdSize</param-name>

    <param-value>100k</param-value>

    </init-param>

    <init-param>

    <param-name>uploadRepositoryPath</param-name>

    <param-value>/temp</param-value>

    </init-param>

    </filter>

    <filter-mapping>

    <filter-name>extensionsFilter</filter-name>

    <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>

    <dispatcher>FORWARD</dispatcher>

    <dispatcher>REQUEST</dispatcher>

    <dispatcher>ERROR</dispatcher>

    </filter-mapping>

    <filter-mapping>

    <filter-name>extensionsFilter</filter-name>

    <url-pattern>*.jsf</url-pattern>

    </filter-mapping>

    <context-param>

    <param-name>facelets.LIBRARIES</param-name>

    <param-value>/WEB-INF/tomahawk.taglib.xml</param-value>

    </context-param>

    <!– Start the Spring listener that loads the application context when the

    Web app starts up. It assumes the context is named WEB-INF/applicationContext.xml

    unless you set a context param called contextConfigLocation to override it. –>

    <listener>

    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>

    <listener>

    <listener-class>

    org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>

    </listener>

    <!– Lets the bean definition file specify scopes of request and session. –>

    <listener>

    <listener-class>

    org.springframework.web.context.request.RequestContextListener</listener-class>

    </listener>

    <filter>

    <filter-name>springSecurityFilterChain</filter-name>

    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>

    </filter>

    <filter-mapping>

    <filter-name>springSecurityFilterChain</filter-name>

    <url-pattern>/*</url-pattern>

    <dispatcher>FORWARD</dispatcher>

    <dispatcher>REQUEST</dispatcher>

    </filter-mapping>

    <context-param>

    <param-name>contextConfigLocation</param-name>

    <param-value>

    /WEB-INF/applicationContext.xml

    /WEB-INF/applicationContext-security.xml

    /WEB-INF/database-context.xml

    </param-value>

    </context-param>

    <servlet>

    <servlet-name>Faces Servlet</servlet-name>

    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>

    </servlet>

    <servlet-mapping>

    <servlet-name>Faces Servlet</servlet-name>

    <url-pattern>*.jsf</url-pattern>

    </servlet-mapping>

    <context-param>

    <param-name>javax.faces.PROJECT_STAGE</param-name>

    <param-value>Development</param-value>

    </context-param>

    <context-param>

    <param-name>javax.faces.CONFIG_FILES</param-name>

    <param-value>/WEB-INF/navigation.xml</param-value>

    </context-param>

    <welcome-file-list>

    <welcome-file>index.jsp</welcome-file>

    <welcome-file>index.html</welcome-file>

    </welcome-file-list>

    </web-app>

    My question is…how it should look the pretty faces.xml? This is my mapping in pretty.xml

    <url-mapping id=”update-profile”>

    <pattern value=”/update-profile/” />

    <view-id>/faces/myFacesExtensionResource/pages/protected/update-profile.jsf</view-id>

    </url-mapping>

    and this is my xhtml:

    <ui:composition xmlns=”http://www.w3.org/1999/xhtml&#8221;

    xmlns:ui=”http://java.sun.com/jsf/facelets&#8221;

    xmlns:components=”http://java.sun.com/jsf/composite/components&#8221;

    xmlns:h=”http://java.sun.com/jsf/html&#8221;

    xmlns:f=”http://java.sun.com/jsf/core&#8221;

    xmlns:t=”http://myfaces.apache.org/tomahawk&#8221;

    template=”/page-templates/main-template.xhtml”>

    <ui:define name=”content”>

    <h:form enctype=”multipart/form-data”>

    <t:inputFileUpload id=”fileupload” value=”#{fileUploadController.myFile}”

    size=”20″ />

    <h:commandButton value=”Update” action=”#{fileUploadController.upload}” style=”float: left;clear: left;background-color:#93BB3A;margin-left: 43%;margin-top: 2%;”/>

    </h:form>

    </ui:define>

    </ui:composition>

    There’s a sysout in upload method from fileUploadController. Nothing in printed in the console. I’m using tomcat 7.

    Am I missing something? Is the url mapping incorrect?

    Thanks

    #20437

    sergiu_oltean
    Participant

    Forgot to say…if the mapping is made this way…I get an error:

    HTTP Status 404 – Could not find resourceloader class for name: pages

    If I write

    <url-mapping id=”update-profile”>

    <pattern value=”/update-profile/” />

    <view-id>/pages/protected/update-profile.jsf</view-id>

    </url-mapping>

    the page loads but the upload doesn’t work .

    #20438

    You appear to still be missing some dispatcher entries in you extensions filter mappings…

    <filter-mapping>

    <filter-name>extensionsFilter</filter-name>

    <url-pattern>*.jsf</url-pattern>

    </filter-mapping>

    Try doing the same as you did for the resources mapping.

    #20439

    sergiu_oltean
    Participant

    Yes Lincoln…that was the solution

    I’ve added

    <filter-mapping>

    <filter-name>extensionsFilter</filter-name>

    <url-pattern>*.jsf</url-pattern>

    <dispatcher>FORWARD</dispatcher>

    <dispatcher>REQUEST</dispatcher>

    <dispatcher>ERROR</dispatcher>

    </filter-mapping>

    and now it works fine.

    Thanks Lincoln. Thanks Christian.

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.

Comments are closed.