Hi everybody, I'm new in the mail-list. I've been studying the framework, I
even read the book Wicket in Action, but I'm having trouble using some kind
of repeater inside a Form, updating and validating the model.
What I'm trying to do is a ListView inside a Form: when the user change the
value of the dropdownchoice, it needs to fire a validator to verify if the
new choice is already in the list. If it is, the validator must call the
"error(validatable)" method from AbstractValidator because I don't want
repeated choices in the list.
First question, anybody knows a simple way to do this?
Second, if I'm on the right way with the code above, how can I get the
listview's model (with the updated values changed by the user, instead of
the default items rendered on the view on the first time) so I can pass this
updated model to my Validator (it needs to know the values in the list to
know wich is repeated).
I just supressed the part of the code that fires my feedback message ( a
kind of Label because I don't want a message per component, just a global
message)
Thanks for any help. Marcel.
private class InputForm extends Form
{
// holds NameWrapper elements
private List<NameWrapper> data;
public InputForm(String name, IFeedback feedback)
{
super(name);
final SubmitLink update = new SubmitLink("update");
add(update);
// add some dummy data
data = new ArrayList<NameWrapper>();
data.add(new NameWrapper("one", 1, "default = 1", true));
data.add(new NameWrapper("two", 2, "default = 2", false));
data.add(new NameWrapper("three", 3, "default = 3", false));
data.add(new NameWrapper("four", 4, "default = 4", true));
final Model dataModel = new Model();
dataModel.setObject(data);
ListView listView = new ListView("list", dataModel)
{
protected void populateItem(ListItem item)
{
NameWrapper wrapper = (NameWrapper)item.getModelObject();
item.add(new Label("name", wrapper.getName()));
item.add(new CheckBox("check", new
PropertyModel(wrapper, "selected")));
DropDownChoice combo = new DropDownChoice("combo"
, new Model(wrapper)
, new ArrayList(Arrays.asList(new
NameWrapper(1000,"mil"), new NameWrapper(2000,"dois mil"), new
NameWrapper(3000,"trĂªs mil")))
, new ChoiceRenderer("comboText","comboId"));
combo.add(new
NameWrapperValidator((List<NameWrapper>)dataModel.getObject()));
item.add(combo);
}
};
*listView.setReuseItems(true); *//i read this line
is very important
add(listView);