1

the problem is with file uploader from primefaces web.xml

<filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

.xhtml

            </h:form>
               ...
            </h:form>
            <h:form enctype="multipart/form-data">
                <p:fileUpload value="#{contratosMB.fileContrato}" mode="simple"/>

                <p:commandButton value="Submit" ajax="false"  
                                 actionListener="#{contratosMB.upload}" update=":form2:formgen:growl"/>
            </h:form>

contratosMB.java

 public void upload() {  
        if(fileContrato != null) {  
            JsfUtil.addSuccessMessage("Se ha cargado correctamente el archivo: " + fileContrato.getFileName()); 
        }  
    }  

I was read some question like this, but nothing was help me... i was add commons-fileupload and commons-io to the project, but dont work not go inside upload method, dont send exception.

SRy
  • 2,901
  • 8
  • 36
  • 57
meyquel
  • 2,134
  • 5
  • 23
  • 42

3 Answers3

1

Try changing

actionListener="#{contratosMB.upload}"

to

action="#{contratosMB.upload}" .

Check this out : Differences between action and actionListener

Community
  • 1
  • 1
SRy
  • 2,901
  • 8
  • 36
  • 57
  • that no chanche any thing...but starting glassfish send this: – meyquel Mar 08 '13 at 13:31
  • Grave: Exception while visiting org/apache/commons/fileupload/FileUploadBase.class of size 12186 java.lang.NullPointerException at org.glassfish.hk2.classmodel.reflect.impl.TypesImpl.getType(TypesImpl.java:78) at org.glassfish.hk2.classmodel.reflect.impl.ModelClassVisitor.visit(ModelClassVisitor.java:119) at org.objectweb.asm.ClassReader.accept(Unknown Source) at org.objectweb.asm.ClassReader.accept(Unknown Source) at org.glassfish.hk2.classmodel.reflect.Parser$5.on(Parser.java:363) – meyquel Mar 08 '13 at 13:34
  • at com.sun.enterprise.v3.server.ReadableArchiveScannerAdapter.handleEntry(ReadableArchiveScannerAdapter.java:171) at com.sun.enterprise.v3.server.ReadableArchiveScannerAdapter.onSelectedEntries(ReadableArchiveScannerAdapter.java:133) at org.glassfish.hk2.classmodel.reflect.Parser.doJob(Parser.java:348) at org.glassfish.hk2.classmodel.reflect.Parser.access$300(Parser.java:70) at org.glassfish.hk2.classmodel.reflect.Parser$3.call(Parser.java:307) at org.glassfish.hk2.classmodel.reflect.Parser$3.call(Parser.java:296) – meyquel Mar 08 '13 at 13:34
  • at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) – meyquel Mar 08 '13 at 13:35
0

it working creating and editing faces-config:

    <dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId> commons-fileupload</artifactId>
    <version>1.2.1</version>
</dependency>
<dependency>
    <groupId>commons-io</groupId>
    <artifactId> commons-io</artifactId>
    <version>1.4</version>
</dependency>

but dont work full for me because form uploader is inside to other form...

   <h:form>
  ...
        <h:form enctype="multipart/form-data">  

            <p:messages showDetail="true"/>  

            <p:fileUpload value="#{contratosMB.fileContrato}" mode="simple"/>  

            <p:commandButton value="Submit" ajax="false"  
                             actionListener="#{contratosMB.upload}"/>  

        </h:form>  
    </h:form>

any body can tell me why??

meyquel
  • 2,134
  • 5
  • 23
  • 42
  • 1
    thank you very much! mine wasn't working either. so I notice that `commons-fileupload` was missing in my project. thank you! – Valter Silva Jun 03 '13 at 02:40
0

Nesting 'form' elements is illegal. Try to upload file in advanced mode and use FileUploadListener to access FileUploadEvent and data.

jpl
  • 347
  • 3
  • 11