1.Introudction
Petite démonstration de la création dynamique de composants avec JSF plus précisement Icefaces... Qui a dit que java c'était lourd et compliqué? ![]()
2. Notre page xhtml, du moins la partie qui nous intéresse
<ice:form>
<ice:panelGrid id="grid" binding="#{dynamicgrid.containerComponent}" columns="2">
</ice:panelGrid>
<ice:commandButton value="Add UI Components" action="#{dynamicgrid.addComponent}" partialSubmit="true"/>
</ice:form>
3. le backing bean
public class DynamicGrid {
public DynamicGrid(){
}
private HtmlPanelGrid containerComponent;
public void addComponent() {
//clean previous component
containerComponent.getChildren().clear();
//dynamically add Child Components to Container Component
for (int i=0;i<10;i++) {
UIColumn col = new UIColumn();
HtmlOutputText ot = new HtmlOutputText();
ot.setValue("test");
col.getChildren().add(ot);
HtmlInputText it = new HtmlInputText();
it.setValue("");
it.setId("label");
col.getChildren().add(it);
if (containerComponent == null) {
containerComponent = new HtmlPanelGrid();
}
containerComponent.getChildren().add(col);
}
}
public HtmlPanelGrid getContainerComponent() {
return containerComponent;
}
public void setContainerComponent(HtmlPanelGrid containerComponent) {
this.containerComponent = containerComponent;
}
}
4. Et sans oublier le faces-config.xml
<managed-bean>
<managed-bean-name>dynamicgrid</managed-bean-name>
<managed-bean-class>ch.devit.dynamic.DynamicGrid</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
Vous devez être identifié pour poster un commentaire.
Le blog de Fabrice Bourqui dit Brutus. Ingénieur en microtechnique de formation, développeur à temps partiel, je vous livre quelques astuces principalement sur les technologies Java et l'OS linux... Merci de votre visite.
Le blog de Fabou dit le Burk ou Brutus
| Lun | Mar | Mer | Jeu | Ven | Sam | Dim |
|---|---|---|---|---|---|---|
| 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 |
Copyright © 2000-2012 - www.developpez.com