Création d'un lien dynamiquement en JSP2
Bonjour.
J'utilise netbeans 6.9 et JSP2.
J'essaye de créer un lien dynamiquement dans une page jsp.
Le lien apparait bien mais n'exécute aucune action.
Voici ma page:
===========
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
Hello from Facelets
<h:panelGrid binding="#{sessionBean1.navigation}">
</h:panelGrid>
<h:outputText value=" > "></h:outputText>
<h:commandLink value="fonctionne" actionListener="#{sessionBean1.retour}">
</h:commandLink>
<h:messages></h:messages>
</h:form>
</h:body>
</html>
Et mon bean:
==========
package programmes;
import java.io.Serializable;
import javax.el.MethodExpression;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.UICommand;
import javax.faces.component.UIOutput;
import javax.faces.component.UIPanel;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.MethodExpressionActionListener;
@ManagedBean
@SessionScoped
public class SessionBean1 implements Serializable {
public SessionBean1() {
}
public UIPanel getNavigation() {
UIPanel f = new UIPanel();
UIOutput s1 = new UIOutput();
s1.setValue(" > ");
f.getChildren().add(s1);
UICommand l = new UICommand();
l.setValue("ne fonctionne pas");
FacesContext facesContext = FacesContext.getCurrentInstance();
MethodExpression me = facesContext.getApplication().getExpressionFactory().createMethodExpression(
facesContext.getELContext(), "#{sessionBean1.retour}",
null, new Class[] {ActionEvent.class});
MethodExpressionActionListener meal = new MethodExpressionActionListener(me);
l.addActionListener(meal);
l.setRendererType("javax.faces.Link");
f.getChildren().add(l);
return f;
}
public void retour(ActionEvent ev) throws Exception {
ExternalContext facesContext = FacesContext.getCurrentInstance().getExternalContext();
System.out.println("retour");
facesContext.redirect("http://www.developpez.net");
}
}
Merci pour votre aide.