Dynamic form avec Jsf UI component Aide
Bonsoir ,
Je voudrais créer un formulaire dynamique via le code java. pour cela j'ai fait ceci
Code:
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
| HtmlSelectManyCheckbox list = (HtmlSelectManyCheckbox)app.createComponent(HtmlSelectManyCheckbox.COMPONENT_TYPE);
compSetValue( list, "#{candidatCtr.nouvellelist}" );
UISelectItems selectItems = (UISelectItems)app.createComponent(UISelectItems.COMPONENT_TYPE);
List<SelectItem> options = new ArrayList<SelectItem>();
//Afficher les test du candidat lors de son authentification
listtestcandidat = testcandidatBuss.consulterTestsCandidatSelonId(candidatloginForTest.getIdcandidat());
for(int i = 0 ; i<listtestcandidat.size();i++){
options.add(new SelectItem(i, listtestcandidat.get(i).getTests().getLibelle()));
}
selectItems.setValue(options);
list.getChildren().add(selectItems);
grid.getChildren().add(list);
Random rnd = new Random();
int random = rnd.nextInt( 200000 );
HtmlOutputText lineavantbreakfinish = new HtmlOutputText();
lineavantbreakfinish.setValue("</br>");
lineavantbreakfinish.setEscape(false);
compSetId( lineavantbreakfinish, "linebreakavantfinish"+random );
grid.getChildren().add(lineavantbreakfinish);
CommandButton monbutton = new CommandButton();
monbutton.setValue("Finish");
monbutton.setStyle("border-radius:7px;margin-left:872px;color:#8B4513");
compSetId( monbutton, "monbutton");
grid.getChildren().add(monbutton);
monbutton.addActionListener(new ActionListener() {
public void processAction(ActionEvent event) throws AbortProcessingException {
System.out.println("button clicked");
System.out.println(nouvellelist.size());
for(int i = 0 ; i< nouvellelist.size();i++){
System.out.println(nouvellelist.get(i).toString());
System.out.println(nouvellelist.size());
}
}
});...return grid |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| private void compSetValue( UIInput comp, String elExpression )
{
ELContext elContext = FacesContext.getCurrentInstance().getELContext();
ValueExpression val1 = FacesContext.getCurrentInstance().
getApplication().
getExpressionFactory().
createValueExpression( elContext,
elExpression,
Object.class);
comp.setValueExpression( "value", val1 );
} // compSetValue |
Le problème c'est que en exécutant ma page j'obtiens bien mes checkboxes et sont crées mais le problème c'est au niveau de nouvellelist parce que en sélectionnant plusieurs chekboxes et en parcourant la liste j'ai toujours nouvellelist.size() = 0 et je sais pas pourquoi.
Est-ce-que vous pouvez m'aider s'il vous plait?
Merci