Command not fired with multipart form (JSF 2.2)

Splash Forums PrettyFaces Users Command not fired with multipart form (JSF 2.2)

This topic contains 35 replies, has 8 voices, and was last updated by  biksg 1 year, 6 months ago.

Viewing 15 posts - 1 through 15 (of 36 total)
  • Author
    Posts
  • #24826

    rvcoutinho
    Participant

    I’ve been trying to use the new h:inputFile from JSF 2.2, but I cannot get it to work. Ever since I have changed the “enctype” attribute of the “h:form” tag, the action is not being invoked anymore.

    After making some experiments, it looks like the problem is related to PrettyFaces.

    Here is what I am using:

    The pom.xml fragment:

    <dependency>
    	<groupId>org.ocpsoft.rewrite</groupId>
    	<artifactId>rewrite-servlet</artifactId>
    	<version>2.0.5.Final</version>
    	<scope>compile</scope>
    </dependency>
    <dependency>
    	<groupId>org.ocpsoft.rewrite</groupId>
    	<artifactId>rewrite-config-prettyfaces</artifactId>
    	<version>2.0.5.Final</version>
    	<scope>compile</scope>
    </dependency>

    A pretty-config.xml example:

    <url-mapping id="how">
    	<pattern value="/como-funciona/" />
    	<view-id value="/how.jsf" />
    </url-mapping>

    A link example:
    <h:link outcome="pretty:how" styleClass="featured-text-1">Como funciona</h:link>

    The form:
    <h:form id="idea-create-form" enctype="multipart/form-data">

    Any suggestions?

    • This topic was modified 2 years, 11 months ago by  rvcoutinho.
    • This topic was modified 2 years, 11 months ago by  rvcoutinho.
    • This topic was modified 2 years, 11 months ago by  rvcoutinho.
    #24830

    Hmmm. That’s weird. I also use enctype="multipart/form-data" sometimes and everything works fine.

    Could you try to remove the mapping from the configuration and access the page directly via /how.jsf and check if it works in this case?

    #24840

    rvcoutinho
    Participant

    Christian,

    Thanks for the response. I completely disabled PrettyFaces and Rewrite, and the problem still occurs. So, it is probably not related to PrettyFaces. I will keep digging.

    I appreciate your response anyway.

    #26033

    rvcoutinho
    Participant

    Hi, Christian.

    There was a bug on the WildFly version at that time. But it has been fixed.

    The problem persists though.

    It looks like pretty faces might be messing with the multipart configuration of the new Servlet 3.1.

    Do you have any idea on how to solve it?

    Thanks in advance.

    • This reply was modified 2 years, 4 months ago by  rvcoutinho.
    • This reply was modified 2 years, 4 months ago by  rvcoutinho.
    #26036

    I think I know what is causing this. The problem is that Rewrite calls HttpServletRequest.getParameter*() from a servlet filter which is not explicitly allowed for Servlet 3.1 multipart requests. For Tomcat there is a known workaround. But I’m not sure if there is a way in Wildfly to do something similar. Here are some references:

    http://ocpsoft.org/rewrite/docs/faq (See “Why are file uploads not working correctly any more?”)
    http://ocpsoft.org/support/topic/file-upload-not-working-with-join/

    #26038

    rvcoutinho
    Participant

    Hi.

    I tried that before posting. I had no luck with the context.xml.

    Thank you anyway.

    #26040

    Hmm, @Christian, do you think this is worth asking about on the WildFly mailing list? I’m not sure I see a great solution for this.

    #26041

    Are we sure the problem is not due to the fact that we wrap the inbound request with our own, which might hide the fact that the request is actually a Multi-part request? I wonder if the servlet spec dictates how those requests need to be represented. Afaik it was non-standard, but I could be wrong.

    #26047

    rvcoutinho
    Participant

    Hi,

    I have been debugging the rewrite lib for a while. But I have not been able to find the problem yet.

    Do you guys want a simple project in order to test it?

    Thank you.

    #26048

    Here is my test app:

    https://github.com/chkal/rewrite-multipart

    After deploying to Wildfly, open this URL:

    http://localhost:8080/rewrite-multipart/upload.jsf

    Try uploading a file. This should work fine.

    The open UploadConfigProvider and add the Join to the configuration. Redeploy and open the following URL:

    http://localhost:8080/rewrite-multipart/upload

    The upload will not work any more.

    #26072

    rvcoutinho
    Participant

    Hi,

    Thanks for the effort. Any suggestions?

    #26073

    Unfortunately I didn’t find any time to have a deeper look at this issue. But this sample app may be a good starting point for debugging.

    #26165

    Janario Oliveira
    Participant

    Hi,

    I’m migrating a project to wildfly and I have the same problem.
    After some debugging I found in jsf-impl used in wildfly(2.2.5-jbossorg-3) a point that is evaluating different.
    com.sun.faces.renderkit.ResponseStateManagerImpl.isPostback():84

    The postback method doesn’t find the request parameter “javax.faces.ViewState” so it jumps from restoreView to renderResponse phase.

    After that I did some debugging in RewriteFilter.
    So evaluating request.getParameter(“javax.faces.ViewState”) in org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter():155 looks like:

    – not multipart request with rewrite – show the parameter
    – multipart request without rewrite – show the parameter
    – multipart request with rewrite – parameter comes null

    Do you have any idea why this is happening?

    #26168

    Could you give Rewrite 2.0.12.Final a try which was just released? It fixes some issues that caused problems with multipart requests on Wildfly. See

    http://ocpsoft.org/support/topic/npe-in-httprewritewrappedrequest/

    #26184

    Janario Oliveira
    Participant

    Hi, I tried in 2.0.12.Final and also in 2.0.13.Final-SNAPSHOT. Same happens.

    It works with this workaround:

    1 – Add undertow-servlet as provided dependency:

            <dependency>
                <groupId>io.undertow</groupId>
                <artifactId>undertow-servlet</artifactId>
                <version>1.0.0.Final</version><!--same version o wildfly-->
                <scope>provided</scope>
            </dependency>
    

    2 – extends DefaultServlet from undertow and add @MultipartConfig

    
    @WebServlet(name = io.undertow.servlet.handlers.ServletPathMatches.DEFAULT_SERVLET_NAME, urlPatterns = "/*")
    @MultipartConfig
    public class MultipartDefaultServlet extends io.undertow.servlet.handlers.DefaultServlet { }
    

    After that the parameters will appears in the filter and also be able to invoke jsf actions.

    The problem is that WildFly associate a parser according to the servlet mapped

    
    HttpServletRequestImpl.parseFormData
      io.undertow.server.handlers.form.FormEncodedDataDefinition always added
      io.undertow.server.handlers.form.MultiPartParserDefinition only added in multipart servlets, DefaultServlet doesn't handle multipart.
    

    If I map FacesServlet to same pattern of URLMapping FacesServlet will handle multipart.

    Trying to reproduce(without the workaround) I create a simple html(multipart.html) and try to see the parameters in a WebFilter

    
    <form enctype="multipart/form-data" method="post">
        <input name="testeParam" value="testeValue"/>
        <input type="submit"/>
    </form>
    
    
    @WebFilter(urlPatterns = "/*")
    public class TestFilter implements Filter {
      doFilter
         request.getParameterMap()
    }
    

    The parameters are always empty. In JBoss same happens but when it is a request of a rewrite mapped(URLMapping) the parameters came in the filter.

    So, What do you think? Is it a bug in WildFly? but in basic sample(multipart.html) parameters are empty even in JBoss

Viewing 15 posts - 1 through 15 (of 36 total)

You must be logged in to reply to this topic.

Comments are closed.