RicardoCostaTW Posted March 19, 2015 at 11:47 AM Report Share #579815 Posted March 19, 2015 at 11:47 AM (edited) Olá, Estou a tentar criar várias dropdown na framework Wicket, mas não sei como implementar um numeor dinâmico de dropdowns porque na view só defino uma... add(new DropDownChoice("authors", new PropertyModel(author, "name"), similiarAuthors, new IChoiceRenderer() { @Override public Object getDisplayValue(Object t) { return t.toString(); } @Override public String getIdValue(Object t, int i) { if (i < 0) { i = 0; } return String.valueOf(similiarAuthors.get(i).getId()); } })); este pequeno snippet é suposto ser utilizado dentro de um loop para criar dinâmicamente dropdown com informação da lista similiarAuthors. Eu não estou a conseguir porque apenas consigo definir na View uma dropdown de cada vez: <wicket:extend> <div wicket:id="label_selectBox"/> <select wicket:id="authors"/> </wicket:extend> Edited March 19, 2015 at 11:48 AM by RicardoCostaTW Link to comment Share on other sites More sharing options...
RicardoCostaTW Posted March 19, 2015 at 12:45 PM Author Report Share #579818 Posted March 19, 2015 at 12:45 PM Descobri uma forma usando fragments. código da view: <wicket:fragment wicket:id="fragment1"> <select wicket:id="authors"/> </wicket:fragment> Código do model: Loop loop = new Loop("list", dropDowns.size()) { @Override protected void populateItem(LoopItem li) { int index = li.getIndex()+1; String fragmentId = "fragment1"; li.add(new Fragment1("panel", fragmentId, dropDowns, index)); } }; add(loop); public class Fragment1 extends Fragment { public Fragment1(String id, String markupId, List<DropDownChoice> dropDowns, int index) { super(id, markupId, MixBook.this); add(dropDowns.get(index-1)); } } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now