0

i'm new in java & jsf framework. I have a situation and make me realy confused. I'm trying to create upload form in jsf, the backing bean is request scoped, user must login for using this form. when I test to submit form, the validation message its not appear, the form just refresh without any validation/required message. I try to find the answer in google or stackoverflow but it not works. However i can upload my files when i try create simple application like my form below, without login function.

My form is look like this:

<h:form id="frMember" enctype="multipart/form-data">
<h:inputText id="username" value="#{memberForm.email}" required="true" requiredMessage="username_required_message" pt:placeholder="username"/><br/><br/>
<h:inputFile value="#{memberForm.fileFoto}" required="true" requiredMessage="file_required_message"/><br/>
<h:commandButton value="upload" action="#{memberForm.upload()}" class="btn btn-danger"/>
</h:form>

I'm using glassfish 4, JSF 2.2.7, Netbeans 8 and i'm not used 3rd party like tomahawk fileupload. I also have try googling and searching through stackoverflow for solving my problem, but still i can't solved it.

updated

this is my controller

public class MemberFormView implements Serializable {        
    private Part fileFoto;

    /**
    * Creates a new instance of MemberFormView
    */
    public MemberFormView() {
    }

    public void upload() throws IOException {
        String fileName = FilenameUtils.getName(fileFoto.getName());
        String contentType = fileFoto.getContentType();
        try (InputStream input = fileFoto.getInputStream()) {
            Files.copy(input, new File("/var/AppFile/tmp/", fileFoto.getName()).toPath());
        }
    }
}

and this is my faces-config.xml

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
              xmlns="http://xmlns.jcp.org/xml/ns/javaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
    <managed-bean>
        <managed-bean-name>memberForm</managed-bean-name>
        <managed-bean-class>controller.member.MemberFormView</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
</faces-config>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Capt. Crunch
  • 1
  • 1
  • 1
  • show your controller source code what annotated by `@ManagedBean` – Vy Do Jun 09 '16 at 06:36
  • @dovy i have update my post – Capt. Crunch Jun 09 '16 at 07:12
  • try something like this: http://www.primefaces.org/showcase/ui/file/upload/basic.xhtml – Vy Do Jun 09 '16 at 07:26
  • 1
    ok i will try... but why using primefaces if jsf already have ? – Capt. Crunch Jun 09 '16 at 07:49
  • Please don't use [java] tag when asking questions about [jsf] or any other Java EE related API. You will otherwise get knee-jerk comments/answers from users knowing nothing about JSF, which would only further confuse you. Use [java] tag only if a problem is demonstratable using a Java application class with a `main()` method and/or the technical question is about the JLS. In such case, the relevance of Java EE related tags such as [jsf] must be reconsidered (usually, they should be dropped in such case). – BalusC Jun 09 '16 at 07:54
  • sorry about that, thanks for changing the tag – Capt. Crunch Jun 09 '16 at 07:57
  • As to your concrete problem, are you indeed saying that the file upload works fine when you don't require a login? – BalusC Jun 09 '16 at 07:58
  • yes, i try to create simple project without login and it works fine. but when i try to implement in my real code, it doesn't work. the form just refresh without validation message appearing. – Capt. Crunch Jun 09 '16 at 08:02
  • If the login is causing all the trouble, why are you in your question focusing only on the upload form being the cause, not on the login being the cause? Or are you implying that a regular and non-upload form continues to work fine even when logged-in? Nonetheless, in order to help us to better help you, you should at least include sufficient information in the question in such way so that we can reproduce exactly your problem when starting with a scratchpad project using bare defaults and most recent versions. See also http://stackoverflow.com/tags/jsf/info – BalusC Jun 09 '16 at 08:09
  • non-upload form work fine when logged-in, my problem is form with upload. i try to change using but it doesn't help. – Capt. Crunch Jun 09 '16 at 08:16
  • Well, then you'd need to tell what exactly you're doing on a logged-in request. It is clear that the upload at its own works perfectly fine, but that some login-related checks are corrupting the multipart/form-data request. Perhaps you're examing a request parameter in some servlet filter for some reason? Still, posting a MCVE will increase chance in getting answers or duplicates sooner. – BalusC Jun 09 '16 at 12:49
  • When making MCVE, I found something weird. So i making new project just like my project for testing but this time i remove unnecessary 3rd party library and then i notice that rewrite servlet is the problem. I'm using this servlet for making pretty url, but i don't understand why this library become a problem? So right now rewrite servlet is remove from my library and everything works fine. Thanks BalusC for your help :) – Capt. Crunch Jun 10 '16 at 03:13

0 Answers0