Bonjour à tous,

J'aimerais faire un upload de plusieurs pièces jointes, j’ai essayé avec une seule pièce jointe et ça marche .

Maintenant quand il s’agit de plusieurs boutons upload et plusieurs boutons parcourir ça veut pas marcher, je n'utilise pas les richefaces mais seulement le tomahawk-1.1.8, car j'ai pas beaucoup de temps pour apprendre le truc des richesfaces et c'est un peut compliqué pour configurer son projet, d’autre part j'utilise jsf RI 1.1.0.1 .

Finalement voila les fichiers de mon projet .

web.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>/WEB-INF/faces-config.xml</param-value>
  </context-param>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
 
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
 
<filter>
    <filter-name>extensionsFilter</filter-name>
        <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
           <init-param>
        <description>
            Set the size limit for uploaded files.
                Format: 10  - 10 bytes
                        10k - 10 KB
                        10m - 10 MB
                        1g  - 1 GB
        </description>
        <param-name>uploadMaxFileSize</param-name>
        <param-value>100m</param-value>
    </init-param>
    <init-param>
        <description>
            Set the threshold size - files below this limit are stored 
            in memory, files above this limit are stored on disk.
                Format: 10  - 10 bytes
                        10k - 10 KB
                        10m - 10 MB
                        1g  - 1 GB
        </description>
        <param-name>uploadThresholdSize</param-name>
        <param-value>100k</param-value>
    </init-param>
    <init-param>
        <description>
            Set the path where the intermediary files will be stored.
        </description>
        <param-name>uploadRepositoryPath</param-name>
        <param-value>/temp</param-value>
    </init-param>
 
</filter>
 
<filter-mapping>
         <filter-name>extensionsFilter</filter-name>
         <url-pattern>*.jsf</url-pattern>
</filter-mapping>
 
<filter-mapping>
          <filter-name>extensionsFilter</filter-name>
          <url-pattern>/faces/*</url-pattern>
</filter-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>
monbean :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 
public class MyBean {
 
    // Init ---------------------------------------------------------------------------------------
 
    private UploadedFile uploadedFile;
    private String fileName;
 
    // Actions ------------------------------------------------------------------------------------
 
    public void submit() {
 
        // Just to demonstrate what information you can get from the uploaded file.
        System.out.println("File type: " + uploadedFile.getContentType());
        System.out.println("File name: " + uploadedFile.getName());
        System.out.println("File size: " + uploadedFile.getSize() + " bytes");
 
        try {
            // Precreate an unique file and then write the InputStream of the uploaded file to it.
            String uploadedFileName = FileUtil.trimFilePath(uploadedFile.getName());
            File uniqueFile = FileUtil.uniqueFile(new File("c:/upload"),uploadedFileName);
            FileUtil.write(uniqueFile, uploadedFile.getInputStream());
            fileName = uniqueFile.getName();
 
            // Show succes message.
            FacesContext.getCurrentInstance().addMessage("uploadForm", new FacesMessage(
                FacesMessage.SEVERITY_INFO, "File upload succeed!", null));
 
        } catch (IOException e) {
 
            // Show error message.
            FacesContext.getCurrentInstance().addMessage("uploadForm", new FacesMessage(
                FacesMessage.SEVERITY_ERROR, "File upload failed with I/O error.", null));
 
            // Always log stacktraces.
            e.printStackTrace();
        }
    }
 
    // Getters ------------------------------------------------------------------------------------
 
    public UploadedFile getUploadedFile() {
        return uploadedFile;
    }
 
    public String getFileName() {
        return fileName;
    }
 
    // Setters ------------------------------------------------------------------------------------
 
    public void setUploadedFile(UploadedFile uploadedFile) {
        this.uploadedFile = uploadedFile;
    }
 
}
la page jsp :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>
 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<f:view>
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>File upload test</title>
        </head>
        <body>
 
                <br />
 
				<h:dataTable value="#{bean_acte.pjd_Acte}" var="PJD" border="1">
					<h:column id="Code_Pjd"> <h:outputText value="#{PJD.id.pjd.codePjd}" />
						<f:facet name="header">
							<h:outputText value="Code" />
						</f:facet>
					</h:column>
					<h:column id="Titre_Pjd"><h:outputText value="#{PJD.id.pjd.titrePjd}" />
						<f:facet name="header">
							<h:outputText value="Titre" />
						</f:facet>
					</h:column>
					<h:column id="Parcourir"> 
					  <h:form id="uploadForm" enctype="multipart/form-data">
					<t:inputFileUpload id="file" value="#{bean_acte.uploadedFile}" required="true" />
					<h:commandButton value="Submit" action="#{bean_acte.submit}" />
					</h:form>
						<f:facet name="header">
						<h:outputText value="Joindre" />
						</f:facet>
					</h:column>
				</h:dataTable>
 
 
 
            <h:outputLink value="file/#{bean_acte.fileName}" rendered="#{bean_acte.fileName != null}">
                Download back
            </h:outputLink>
        </body>
    </html>
</f:view>
Et voila l'erreur que j'ai en retour lorsque je submit le upload :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 
javax.servlet.ServletException: #{bean_acte.submit}: javax.faces.el.EvaluationException: java.lang.NullPointerException
	javax.faces.webapp.FacesServlet.service(FacesServlet.java:209)
	org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:301)
 
cause mère
 
javax.faces.FacesException: #{bean_acte.submit}: javax.faces.el.EvaluationException: java.lang.NullPointerException
	com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:78)
	javax.faces.component.UICommand.broadcast(UICommand.java:312)
	javax.faces.component.UIData.broadcast(UIData.java:657)
	javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
	javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
	com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
	com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
	com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
	javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
	org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:301)
 
cause mère
 
javax.faces.el.EvaluationException: java.lang.NullPointerException
	com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:130)
	com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
	javax.faces.component.UICommand.broadcast(UICommand.java:312)
	javax.faces.component.UIData.broadcast(UIData.java:657)
	javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
	javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
	com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
	com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
	com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
	javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
	org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:301)
Merci à vous.