Bonjour,

J'utilise le code suivant pour pouvoir créer un site, dont la section 'page' est obtenue dynamiquement avec une variable, et tout en gardant le reste de l'architecture du site :

principal.xhtml :
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
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:c="http://java.sun.com/jsp/jstl/core">
 
	<h:head>
 
	<title>Miagetest-JSF</title>
	</h:head>
 
	<h:body>
	<h1>Miagetest-JSF</h1>
 
	infoSession
 
	<ui:include src="menu.xhtml" />
 
	${message}
 
	<ui:include src="#{action.page}.xhtml" />
 
	</h:body>
	</html>
Voici un exemple de sous page :

creerClientForm.xhtml :
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
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html">
 
 
<h2>Créer client</h2>
 
<h:form>
	<h:panelGrid>
	    <h:inputText label="Nom" value="#{clientAction.nom}" />
	    <h:inputText label="Prenom" value="#{clientAction.prenom}" />
	    <h:commandButton value="Enregistrer client" action="#{clientAction.newClient}"/> 
	</h:panelGrid>
</h:form>
 
</ui:composition>
En voici un autre :

listeClients.xhtml :
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
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html">
 
	<h2>Liste clients</h2>
 
	<h:dataTable value="#{clientAction.clients}" border="1" var="client">
 
		<h:column>
			<f:facet name="header">id</f:facet>
    		#{client.id}
    	</h:column>
 
    	<h:column>
			<f:facet name="header">Nom</f:facet>
    		#{client.nom}
    	</h:column>
 
    	<h:column>
			<f:facet name="header">Prénom</f:facet>
    		#{client.prenom}
    	</h:column>    	   	 
 
	</h:dataTable>
 
</ui:composition>
Voici mon bean JSF principal :

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
package beans;
 
import gestion.GestionnaireRemote;
 
import java.io.IOException;
 
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
 
@ManagedBean
@RequestScoped
public class Action {
 
    @EJB
    GestionnaireRemote gestionnaire;
 
    private String page;
 
    private String message;
 
    public final String SUCCESS = "success";
 
    public String getPage() {
 
        if(page == null)
            return "default";
 
        return page;
    }
 
    public void setPage(String page) {
        this.page = page;
    }
 
    public String getMessage() {
        return message;
    }
 
    public void setMessage(String message) {
        this.message = message;
    }
 
    public String returnSuccessPageMethodName()
    {
        //Si par exemple on est dans la méthode listeClients(), on aura page = "listeClients";
        page = Thread.currentThread().getStackTrace()[2].getMethodName();        
        return SUCCESS;
    }
 
    public String listeClients()
    {
        return returnSuccessPageMethodName();
    }
 
    public String creerClientForm()
    {
        return returnSuccessPageMethodName();
    }
 
 
}
Voici mon bean dédié :

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
package beans;
 
import java.util.List;
 
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
 
import dao.EntityAlreadyExistsException;
import entities.Client;
 
@ManagedBean
@RequestScoped
public class ClientAction extends Action {
 
    private String nom;
 
    private String prenom;
 
 
    public void setNom(String nom) {
        this.nom = nom;
    }
 
    public void setPrenom(String prenom) {
        this.prenom = prenom;
    }
 
    //nécessaire car sinon : The class 'beans.ClientAction' does not have a readable property 'nom'.
    public String getNom() {
        return nom;
    }
 
    public String getPrenom() {
        return prenom;
    }
 
    public List<Client> getClients() {
 
        return (List<Client>) gestionnaire.getAll(Client.class);
 
    }
 
    public void newClient()
    {
        try
        {
            gestionnaire.creerClient(nom, prenom);
            setMessage("Le client a été correctement créé.");
 
        } catch (EntityAlreadyExistsException ex) {
            setMessage(ex.toString());
        }
        //return "SUCCESS";
        //setPage("creerClientForm");
 
    }    
 
}
Ma page 'listeClients' fonctionne très bien, par contre 'creerClientForm' ne fonctionne pas. Les méthodes setNom et setPrenom ne sont pas appelés, et newClient non plus.

Par contre, si je récupère le code de creerClientForm.xhtml sur principal.xhtml, ça marche correctement. Comme si le fait d'avoir le <ui:include src="#{action.page}.xhtml" /> détruisait tout, comme si le form envoyé était perdu en chemin.

Que faut-il modifier pour que creerClientForm.xhtml puisse fonctionner ? Y-a-t-il une manière propre de faire ce genre de chose en JSF? (une sous page dynamique d'une même page principale)

Merci de votre aide.