Hi, I would do something like
1- interface IFieldFactory { boolean canHandle(Variable<Object> variable); Panel createComponenPanel(String id, Variable<Object> variable); } 2- FiledFactoryLocator having a collection of field factories. 3- On your listview for(IFieldFactory factory: locator.getFieldFactories()) { if(factory.canHandle(variable)) { item.add(factory.createComponenPanel(id, variable); } } This way you will get rid of the nasty "ifs" and to support a new type you just have to implement and register a new IFieldFactory. Makes sense? On Mon, May 19, 2014 at 10:49 AM, Valentin Robert <valentin.rob...@gmx.com>wrote: > Hi > > i 'm new with wicket and after searching a solution to my problem, i > couldn't find any solution > Here is what i want to do. > > I would like to build a form where the input type can be textfields, > checkboxes, dropdown, ... > i've seen that some solutions would be to create a new conponent, or to > have multiple containers and set their visibility in java. > however i would like to have something like this : > > HTML > > <wicket:container wicket:id="listInput"> > <input wicket:id="input"id="whatever" type="text" size="40" /> > </wicket:container> > > Java > > add(new ListView<Variable<Object>>("listInput", obj.getList()) > { > > protected void populateItem(ListItem<Variable<Object>> item) > { > final Variable<Object> var = item.getModelObject(); > > if (var.getType().equals("string")) > { > item.add( new Textfield (...)); > } > else if (var.getType().equals("boolean")) > { > item.add( new Checkbox (...)); > } > ...... > > this does not work because i can't had a new checkbox on a component who > has a type=text. > > i tried to do something like add(AttributeModifier.replace("type", > "checkbox")); but i couldn't manage to do what i wanted. > If still think that if i don't want to create a component or have multiple > containers in my html, this is what i should use. > > if someone could help me to do this that would be great, i'm stuck with > this probleme and i didn't like the solutions that i found. > > thank you for taking the time to help me. > -- Regards - Ernesto Reinaldo Barreiro