0

I'm trying to create via programmcode a HtmlSelectOneMenu. This is not the problem. I realised it like this:

final UISelectItem select = (UISelectItem) app.createComponent(UISelectItem.COMPONENT_TYPE);

//Items für DropDownMenü erstellen
List<SelectItem> items = new ArrayList<SelectItem>();
for (int k = 0; k < Gender2.values().length; k++){
    items.add(new SelectItem(Gender2.values()[k]));                
}

//Items dem DropDown Menü zuordnen
UISelectItems selectItems = new UISelectItems();
selectItems.setValue(items);
selectOneRadio = (HtmlSelectOneMenu) app.createComponent(HtmlSelectOneMenu.COMPONENT_TYPE);
selectOneRadio.getChildren().add(selectItems);
testgrid.getChildren().add(selectOneRadio);

When I call this method again, the following error appears: Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception javax.servlet.ServletException: Komponenten-ID j_idt3:j_id5 was already found

Want can I do against this error?

Kukeltje
  • 11,924
  • 4
  • 19
  • 44
Yves
  • 35
  • 1
  • 8

1 Answers1

-1

You should assign an unique IDs to components that you are creating with setId() method.

You can ether generate id's on your own, or use:

FacesContext.getCurrentInstance().getViewRoot().createUniqueId()

to generate them.

partlov
  • 13,002
  • 6
  • 59
  • 76
  • Hey partlov, thank you for the fast answer. Now is my problem how to generate unique ID's – Yves Jan 17 '13 at 10:27
  • Okay i tried ist with the createUniqueID(), but the erros occurs again. Sommetimes not at the first click, but then when i want to create a new item. – Yves Jan 18 '13 at 10:12
  • 1
    Okay i got ist. I changed the scope of the bean from session to request and now it works! – Yves Jan 22 '13 at 11:55