Créer des composants dynamiquement
j'ai essayé de créer un nouveau inputtext à chaque fois que je clique sur un bouton voila mon code :
mon managed bean
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
private HtmlPanelGrid dynamicPanelGrid ;
public String addQuestion(){
Random rnd=new Random();
Application app = FacesContext.getCurrentInstance().getApplication();
HtmlInputText text = (HtmlInputText) app.createComponent(HtmlInputText.COMPONENT_TYPE);
text.setValue("some text");
text.setId("text"+rnd.nextInt(2000));
dynamicPanelGrid.getChildren().add(text);
return null;
} |
page xhtml
Code:
1 2 3 4 5 6 7
|
<h:panelGrid columns="2">
<h:commandLink value="Ajouter une Nouvelle Question "
action="#{principalBean.questbean.addQuestion()}" />
<h:commandLink value=" Se deconnecter" />
</h:panelGrid>
<h:panelGrid binding="#{principalBean.questbean.dynamicPanelGrid}"/> |
pour la première fois le ça marche et pour la deuxième je reçoie le massage suivant :
javax.servlet.ServletException: L’ID de composant «j_idt5:text1369» a déjà été détecté dans la vue.
javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)