You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Tito <nj...@gmail.com> on 2011/06/01 12:56:09 UTC
Re: Model detached before Validate of FormValidator
I read that is a normal behavior. It's because validation occurs before
model population.
In that way when validation fails model won't be populated.
So I would have to do something like textField.getInput() but I had a
problem to get a model Object from a Palette.
For example:
Palette<Task> palette = new Palette<Task>(.....);
form.add(palette);
form.add(new IFormValidator() {
@Override
public void Validate(Form<?> form) {
// how to get a list of selected tasks???
}
});
So I made validation on "onSubmit" method of form. Now I'm fighting with
localized message to finish.
Thanks!
Tito
2011/5/31 Per Newgro <pe...@gmx.ch>
> Am 31.05.2011 15:10, schrieb Tito:
>
> Is this ok?
>>
>> I have to validate model object but it's detached when validate of form
>> validator is called. How can I make this validation?
>>
>> Thanks
>>
>> Provide some code describing the problem please.
>
> Cheers
> Per
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Model detached before Validate of FormValidator
Posted by Tito <nj...@gmail.com>.
Wow, you tryed hard to do this.
I had no more ideas, I'll try with this.
Thank you very much.
Tito
2011/6/5 Per Newgro <pe...@gmx.ch>
> Hi Tito,
>
> i hope i got a valid solution for you. Please check it:
>
> a) You need to use a bean. I've tried it with simple strings like
> (1,2,7,24)
> and it wasn't working. I think because the renderer is called only with
> index 0.
> I don't know if this is a palette bug or a needed feature.
> b) you have to add the validator to the recorder component. This gets the
> list
> of ids selected in component. (Debug from here
> String[] ids = getIdsOfSelectedChoices(validatable);)
>
> hth
> Per
>
> <code>
>
> package ch.newgro.validpalette;
>
> import java.io.Serializable;
> import java.util.ArrayList;
> import java.util.Collection;
> import java.util.Collections;
> import java.util.List;
>
> import org.apache.wicket.extensions.markup.html.form.palette.Palette;
> import
> org.apache.wicket.extensions.markup.html.form.palette.component.Recorder;
> import org.apache.wicket.markup.html.WebPage;
> import org.apache.wicket.markup.html.form.ChoiceRenderer;
> import org.apache.wicket.markup.html.form.Form;
> import org.apache.wicket.markup.html.form.IChoiceRenderer;
> import org.apache.wicket.model.IModel;
> import org.apache.wicket.model.Model;
> import org.apache.wicket.model.util.ListModel;
> import org.apache.wicket.validation.IValidatable;
> import org.apache.wicket.validation.validator.AbstractValidator;
>
> /**
> * Homepage
> */
> public class HomePage extends WebPage {
>
> class Bean implements Serializable {
>
> public final int id;
> public final String name;
>
> public Bean(int id, String name) {
> this.id = id;
> this.name = name;
> }
>
> @Override
> public String toString() {
> return super.toString().concat(";
> id:").concat(String.valueOf(id)).concat("; name: ").concat(name);
> }
> }
>
> private final List<Bean> beans = new ArrayList<Bean>(beans());
>
> public HomePage() {
> Form<Void> form;
> add(form = new Form<Void>("form"));
> IModel<List<Bean>> model = new ListModel<Bean>(beans);
> Palette<Bean> palette = new Palette<Bean>("palette", model,
> choicesModel(), choiceRenderer(), 10, false) {
> @Override
> protected Recorder<Bean> newRecorderComponent() {
> final Recorder<Bean> result = super.newRecorderComponent();
> result.add(new AbstractValidator<Object>() {
> @Override
> protected void onValidate(IValidatable<Object>
> validatable) {
> String[] ids = getIdsOfSelectedChoices(validatable);
> printSelectedChoicesOf(result, ids);
> }
>
> private String[]
> getIdsOfSelectedChoices(IValidatable<Object> validatable) {
> return ((String) validatable.getValue()).split(",");
> }
>
> private void printSelectedChoicesOf(final Recorder<Bean>
> recorder, String[] idsOfSelectedChocies) {
> IChoiceRenderer<Bean> renderer =
> recorder.getPalette().getChoiceRenderer();
> if (idsOfSelectedChocies.length > 0) {
> for (String id : idsOfSelectedChocies) {
> Collection<? extends Bean> choices =
> recorder.getPalette().getChoices();
> for (Bean choice : choices) {
> if (renderer.getIdValue(choice,
> 0).equals(id)) {
> System.out.println(choice);
> }
> }
> }
> }
> }
> });
> return result;
> }
> };
> form.add(palette);
> }
>
> private List<Bean> beans() {
> return Collections.emptyList(); // Arrays.asList(new Bean(0, "1"),
> new Bean(4, "11"), new Bean(8, "21"));
> }
>
> private IModel<List<? extends Bean>> choicesModel() {
> return Model.ofList(allNames());
> }
>
> private List<? extends Bean> allNames() {
> ArrayList<Bean> result = new ArrayList<Bean>();
> result.add(bean(0, "1"));
> result.add(bean(1, "2"));
> result.add(bean(2, "3"));
> result.add(bean(3, "4"));
> result.add(bean(4, "11"));
> result.add(bean(5, "12"));
> result.add(bean(6, "13"));
> result.add(bean(7, "14"));
> result.add(bean(8, "21"));
> result.add(bean(9, "22"));
> result.add(bean(10, "23"));
> result.add(bean(11, "24"));
> return result;
> }
>
> private Bean bean(int id, String name) {
> return new Bean(id, name);
> }
>
> private IChoiceRenderer<Bean> choiceRenderer() {
> return new ChoiceRenderer<Bean>("name", "id");
> }
>
> }
>
> </code>
>
>
> No problem, thanks for your answer.
>> We always try to find a solution which is fine for me.
>>
>> When I call getSelectedChoices in Validation method it give us an empty
>> List
>> back. It is like the list it is not uploaded before entering the
>> validation
>> method.
>>
>> Thanks for helping me.
>>
>> Regards
>> Tito
>>
>> 2011/6/3 Per Newgro<pe...@gmx.ch>
>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Model detached before Validate of FormValidator
Posted by Per Newgro <pe...@gmx.ch>.
Hi Tito,
i hope i got a valid solution for you. Please check it:
a) You need to use a bean. I've tried it with simple strings like (1,2,7,24)
and it wasn't working. I think because the renderer is called only with
index 0.
I don't know if this is a palette bug or a needed feature.
b) you have to add the validator to the recorder component. This gets
the list
of ids selected in component. (Debug from here
String[] ids = getIdsOfSelectedChoices(validatable);)
hth
Per
<code>
package ch.newgro.validpalette;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.apache.wicket.extensions.markup.html.form.palette.Palette;
import
org.apache.wicket.extensions.markup.html.form.palette.component.Recorder;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.util.ListModel;
import org.apache.wicket.validation.IValidatable;
import org.apache.wicket.validation.validator.AbstractValidator;
/**
* Homepage
*/
public class HomePage extends WebPage {
class Bean implements Serializable {
public final int id;
public final String name;
public Bean(int id, String name) {
this.id = id;
this.name = name;
}
@Override
public String toString() {
return super.toString().concat(";
id:").concat(String.valueOf(id)).concat("; name: ").concat(name);
}
}
private final List<Bean> beans = new ArrayList<Bean>(beans());
public HomePage() {
Form<Void> form;
add(form = new Form<Void>("form"));
IModel<List<Bean>> model = new ListModel<Bean>(beans);
Palette<Bean> palette = new Palette<Bean>("palette", model,
choicesModel(), choiceRenderer(), 10, false) {
@Override
protected Recorder<Bean> newRecorderComponent() {
final Recorder<Bean> result = super.newRecorderComponent();
result.add(new AbstractValidator<Object>() {
@Override
protected void onValidate(IValidatable<Object>
validatable) {
String[] ids =
getIdsOfSelectedChoices(validatable);
printSelectedChoicesOf(result, ids);
}
private String[]
getIdsOfSelectedChoices(IValidatable<Object> validatable) {
return ((String)
validatable.getValue()).split(",");
}
private void printSelectedChoicesOf(final
Recorder<Bean> recorder, String[] idsOfSelectedChocies) {
IChoiceRenderer<Bean> renderer =
recorder.getPalette().getChoiceRenderer();
if (idsOfSelectedChocies.length > 0) {
for (String id : idsOfSelectedChocies) {
Collection<? extends Bean> choices =
recorder.getPalette().getChoices();
for (Bean choice : choices) {
if (renderer.getIdValue(choice,
0).equals(id)) {
System.out.println(choice);
}
}
}
}
}
});
return result;
}
};
form.add(palette);
}
private List<Bean> beans() {
return Collections.emptyList(); // Arrays.asList(new Bean(0,
"1"), new Bean(4, "11"), new Bean(8, "21"));
}
private IModel<List<? extends Bean>> choicesModel() {
return Model.ofList(allNames());
}
private List<? extends Bean> allNames() {
ArrayList<Bean> result = new ArrayList<Bean>();
result.add(bean(0, "1"));
result.add(bean(1, "2"));
result.add(bean(2, "3"));
result.add(bean(3, "4"));
result.add(bean(4, "11"));
result.add(bean(5, "12"));
result.add(bean(6, "13"));
result.add(bean(7, "14"));
result.add(bean(8, "21"));
result.add(bean(9, "22"));
result.add(bean(10, "23"));
result.add(bean(11, "24"));
return result;
}
private Bean bean(int id, String name) {
return new Bean(id, name);
}
private IChoiceRenderer<Bean> choiceRenderer() {
return new ChoiceRenderer<Bean>("name", "id");
}
}
</code>
> No problem, thanks for your answer.
> We always try to find a solution which is fine for me.
>
> When I call getSelectedChoices in Validation method it give us an empty List
> back. It is like the list it is not uploaded before entering the validation
> method.
>
> Thanks for helping me.
>
> Regards
> Tito
>
> 2011/6/3 Per Newgro<pe...@gmx.ch>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Model detached before Validate of FormValidator
Posted by Tito <nj...@gmail.com>.
No problem, thanks for your answer.
We always try to find a solution which is fine for me.
When I call getSelectedChoices in Validation method it give us an empty List
back. It is like the list it is not uploaded before entering the validation
method.
Thanks for helping me.
Regards
Tito
2011/6/3 Per Newgro <pe...@gmx.ch>
> Afaik no. Your right. I missed the "alidator" part of the interface
> IFormValidator. My explanation was related
> the FromVisitor. Sorry for that.
>
> But you could make palette final and access it inside the validate method.
> Then you could do a palette.|getRecorderComponent().getSelectedChoices().
> This method is accessing
> the component values instead of the model values.
>
> Hth (and sorry for my blindness)
> Per
>
> |
>
>> Does it means that Model of form is populated before Validate?
>> I didn't know that. In that way I also can use palette model in form and
>> it
>> would have to work too.
>>
>> Thanks for the solution!
>>
>> Tito
>>
>> 2011/6/3 Per Newgro<pe...@gmx.ch>
>>
>> Sorry, i missed to say that you have to connect bunsinessModel and
>>> selected
>>> list of palette.
>>> Palette<Task> palette = new Palette<Task>(..., new
>>> PropertyModel<List<Task>>(model, "tasks"), ...);
>>>
>>> Per
>>>
>>> Palette<Task> palette = new Palette<Task>(.....);
>>>
>>>> form.add(palette);
>>>>
>>>> form.add(new IFormValidator() {
>>>>
>>>> @Override
>>>> public void Validate(Form<?> form) {
>>>> // how to get a list of selected tasks???
>>>> }
>>>> });
>>>>
>>>> You have to set the model to the form by assigning the list or wrap it
>>>> in
>>>> a business model.
>>>> Then you can do a form.getModelObject() in validate method and cast it
>>>> to
>>>> the assigned
>>>> list or business model.
>>>>
>>>> Like this
>>>>
>>>> public class MyBusinessModel {
>>>> public List<Task> getTasks() {
>>>> ...
>>>> }
>>>> }
>>>>
>>>> public class MyComponent extends Panel {
>>>> public MyComponent(String id, IModel<MyBusinessModel> model) {
>>>> super(id, model);
>>>> Form<MyBusinessModel> form = new Form("form", model);
>>>>
>>>> Palette<Task> palette = new Palette<Task>(.....);
>>>> form.add(palette);
>>>>
>>>> form.add(new IFormValidator() {
>>>>
>>>> @Override
>>>> public void Validate(Form<?> form) {
>>>> MyBusinessModel model = (MyBusinessModel) form.getModelObject();
>>>> // how to get a list of selected tasks???
>>>> List<Task> selectedTasks = model.getTasks();
>>>> }
>>>> });
>>>>
>>>> }
>>>> }
>>>>
>>>>
>>>> Hth
>>>> Per
>>>>
>>>> I read that is a normal behavior. It's because validation occurs before
>>>>> model population.
>>>>> In that way when validation fails model won't be populated.
>>>>>
>>>>> So I would have to do something like textField.getInput() but I had a
>>>>> problem to get a model Object from a Palette.
>>>>> For example:
>>>>>
>>>>> Palette<Task> palette = new Palette<Task>(.....);
>>>>> form.add(palette);
>>>>>
>>>>> form.add(new IFormValidator() {
>>>>>
>>>>> @Override
>>>>> public void Validate(Form<?> form) {
>>>>> // how to get a list of selected tasks???
>>>>> }
>>>>> });
>>>>>
>>>>> So I made validation on "onSubmit" method of form. Now I'm fighting
>>>>> with
>>>>> localized message to finish.
>>>>>
>>>>> Thanks!
>>>>> Tito
>>>>>
>>>>> 2011/5/31 Per Newgro<pe...@gmx.ch>
>>>>>
>>>>> Am 31.05.2011 15:10, schrieb Tito:
>>>>>
>>>>>> Is this ok?
>>>>>>
>>>>>> I have to validate model object but it's detached when validate of
>>>>>>> form
>>>>>>> validator is called. How can I make this validation?
>>>>>>>
>>>>>>> Thanks
>>>>>>>
>>>>>>> Provide some code describing the problem please.
>>>>>>>
>>>>>>> Cheers
>>>>>> Per
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>
Re: Model detached before Validate of FormValidator
Posted by Per Newgro <pe...@gmx.ch>.
Afaik no. Your right. I missed the "alidator" part of the interface
IFormValidator. My explanation was related
the FromVisitor. Sorry for that.
But you could make palette final and access it inside the validate method.
Then you could do a
palette.|getRecorderComponent().getSelectedChoices(). This method is
accessing
the component values instead of the model values.
Hth (and sorry for my blindness)
Per
|
> Does it means that Model of form is populated before Validate?
> I didn't know that. In that way I also can use palette model in form and it
> would have to work too.
>
> Thanks for the solution!
>
> Tito
>
> 2011/6/3 Per Newgro<pe...@gmx.ch>
>
>> Sorry, i missed to say that you have to connect bunsinessModel and selected
>> list of palette.
>> Palette<Task> palette = new Palette<Task>(..., new
>> PropertyModel<List<Task>>(model, "tasks"), ...);
>>
>> Per
>>
>> Palette<Task> palette = new Palette<Task>(.....);
>>> form.add(palette);
>>>
>>> form.add(new IFormValidator() {
>>>
>>> @Override
>>> public void Validate(Form<?> form) {
>>> // how to get a list of selected tasks???
>>> }
>>> });
>>>
>>> You have to set the model to the form by assigning the list or wrap it in
>>> a business model.
>>> Then you can do a form.getModelObject() in validate method and cast it to
>>> the assigned
>>> list or business model.
>>>
>>> Like this
>>>
>>> public class MyBusinessModel {
>>> public List<Task> getTasks() {
>>> ...
>>> }
>>> }
>>>
>>> public class MyComponent extends Panel {
>>> public MyComponent(String id, IModel<MyBusinessModel> model) {
>>> super(id, model);
>>> Form<MyBusinessModel> form = new Form("form", model);
>>>
>>> Palette<Task> palette = new Palette<Task>(.....);
>>> form.add(palette);
>>>
>>> form.add(new IFormValidator() {
>>>
>>> @Override
>>> public void Validate(Form<?> form) {
>>> MyBusinessModel model = (MyBusinessModel) form.getModelObject();
>>> // how to get a list of selected tasks???
>>> List<Task> selectedTasks = model.getTasks();
>>> }
>>> });
>>>
>>> }
>>> }
>>>
>>>
>>> Hth
>>> Per
>>>
>>>> I read that is a normal behavior. It's because validation occurs before
>>>> model population.
>>>> In that way when validation fails model won't be populated.
>>>>
>>>> So I would have to do something like textField.getInput() but I had a
>>>> problem to get a model Object from a Palette.
>>>> For example:
>>>>
>>>> Palette<Task> palette = new Palette<Task>(.....);
>>>> form.add(palette);
>>>>
>>>> form.add(new IFormValidator() {
>>>>
>>>> @Override
>>>> public void Validate(Form<?> form) {
>>>> // how to get a list of selected tasks???
>>>> }
>>>> });
>>>>
>>>> So I made validation on "onSubmit" method of form. Now I'm fighting with
>>>> localized message to finish.
>>>>
>>>> Thanks!
>>>> Tito
>>>>
>>>> 2011/5/31 Per Newgro<pe...@gmx.ch>
>>>>
>>>> Am 31.05.2011 15:10, schrieb Tito:
>>>>> Is this ok?
>>>>>
>>>>>> I have to validate model object but it's detached when validate of form
>>>>>> validator is called. How can I make this validation?
>>>>>>
>>>>>> Thanks
>>>>>>
>>>>>> Provide some code describing the problem please.
>>>>>>
>>>>> Cheers
>>>>> Per
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
Re: Model detached before Validate of FormValidator
Posted by Tito <nj...@gmail.com>.
Does it means that Model of form is populated before Validate?
I didn't know that. In that way I also can use palette model in form and it
would have to work too.
Thanks for the solution!
Tito
2011/6/3 Per Newgro <pe...@gmx.ch>
> Sorry, i missed to say that you have to connect bunsinessModel and selected
> list of palette.
> Palette<Task> palette = new Palette<Task>(..., new
> PropertyModel<List<Task>>(model, "tasks"), ...);
>
> Per
>
> Palette<Task> palette = new Palette<Task>(.....);
>> form.add(palette);
>>
>> form.add(new IFormValidator() {
>>
>> @Override
>> public void Validate(Form<?> form) {
>> // how to get a list of selected tasks???
>> }
>> });
>>
>> You have to set the model to the form by assigning the list or wrap it in
>> a business model.
>> Then you can do a form.getModelObject() in validate method and cast it to
>> the assigned
>> list or business model.
>>
>> Like this
>>
>> public class MyBusinessModel {
>> public List<Task> getTasks() {
>> ...
>> }
>> }
>>
>> public class MyComponent extends Panel {
>> public MyComponent(String id, IModel<MyBusinessModel> model) {
>> super(id, model);
>> Form<MyBusinessModel> form = new Form("form", model);
>>
>> Palette<Task> palette = new Palette<Task>(.....);
>> form.add(palette);
>>
>> form.add(new IFormValidator() {
>>
>> @Override
>> public void Validate(Form<?> form) {
>> MyBusinessModel model = (MyBusinessModel) form.getModelObject();
>> // how to get a list of selected tasks???
>> List<Task> selectedTasks = model.getTasks();
>> }
>> });
>>
>> }
>> }
>>
>>
>> Hth
>> Per
>>
>>> I read that is a normal behavior. It's because validation occurs before
>>> model population.
>>> In that way when validation fails model won't be populated.
>>>
>>> So I would have to do something like textField.getInput() but I had a
>>> problem to get a model Object from a Palette.
>>> For example:
>>>
>>> Palette<Task> palette = new Palette<Task>(.....);
>>> form.add(palette);
>>>
>>> form.add(new IFormValidator() {
>>>
>>> @Override
>>> public void Validate(Form<?> form) {
>>> // how to get a list of selected tasks???
>>> }
>>> });
>>>
>>> So I made validation on "onSubmit" method of form. Now I'm fighting with
>>> localized message to finish.
>>>
>>> Thanks!
>>> Tito
>>>
>>> 2011/5/31 Per Newgro<pe...@gmx.ch>
>>>
>>> Am 31.05.2011 15:10, schrieb Tito:
>>>>
>>>> Is this ok?
>>>>
>>>>> I have to validate model object but it's detached when validate of form
>>>>> validator is called. How can I make this validation?
>>>>>
>>>>> Thanks
>>>>>
>>>>> Provide some code describing the problem please.
>>>>>
>>>> Cheers
>>>> Per
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Model detached before Validate of FormValidator
Posted by Per Newgro <pe...@gmx.ch>.
Sorry, i missed to say that you have to connect bunsinessModel and
selected list of palette.
Palette<Task> palette = new Palette<Task>(..., new
PropertyModel<List<Task>>(model, "tasks"), ...);
Per
> Palette<Task> palette = new Palette<Task>(.....);
> form.add(palette);
>
> form.add(new IFormValidator() {
>
> @Override
> public void Validate(Form<?> form) {
> // how to get a list of selected tasks???
> }
> });
>
> You have to set the model to the form by assigning the list or wrap it
> in a business model.
> Then you can do a form.getModelObject() in validate method and cast it
> to the assigned
> list or business model.
>
> Like this
>
> public class MyBusinessModel {
> public List<Task> getTasks() {
> ...
> }
> }
>
> public class MyComponent extends Panel {
> public MyComponent(String id, IModel<MyBusinessModel> model) {
> super(id, model);
> Form<MyBusinessModel> form = new Form("form", model);
>
> Palette<Task> palette = new Palette<Task>(.....);
> form.add(palette);
>
> form.add(new IFormValidator() {
>
> @Override
> public void Validate(Form<?> form) {
> MyBusinessModel model = (MyBusinessModel) form.getModelObject();
> // how to get a list of selected tasks???
> List<Task> selectedTasks = model.getTasks();
> }
> });
>
> }
> }
>
>
> Hth
> Per
>> I read that is a normal behavior. It's because validation occurs before
>> model population.
>> In that way when validation fails model won't be populated.
>>
>> So I would have to do something like textField.getInput() but I had a
>> problem to get a model Object from a Palette.
>> For example:
>>
>> Palette<Task> palette = new Palette<Task>(.....);
>> form.add(palette);
>>
>> form.add(new IFormValidator() {
>>
>> @Override
>> public void Validate(Form<?> form) {
>> // how to get a list of selected tasks???
>> }
>> });
>>
>> So I made validation on "onSubmit" method of form. Now I'm fighting with
>> localized message to finish.
>>
>> Thanks!
>> Tito
>>
>> 2011/5/31 Per Newgro<pe...@gmx.ch>
>>
>>> Am 31.05.2011 15:10, schrieb Tito:
>>>
>>> Is this ok?
>>>> I have to validate model object but it's detached when validate of
>>>> form
>>>> validator is called. How can I make this validation?
>>>>
>>>> Thanks
>>>>
>>>> Provide some code describing the problem please.
>>> Cheers
>>> Per
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Model detached before Validate of FormValidator
Posted by Per Newgro <pe...@gmx.ch>.
Palette<Task> palette = new Palette<Task>(.....);
form.add(palette);
form.add(new IFormValidator() {
@Override
public void Validate(Form<?> form) {
// how to get a list of selected tasks???
}
});
You have to set the model to the form by assigning the list or wrap it
in a business model.
Then you can do a form.getModelObject() in validate method and cast it
to the assigned
list or business model.
Like this
public class MyBusinessModel {
public List<Task> getTasks() {
...
}
}
public class MyComponent extends Panel {
public MyComponent(String id, IModel<MyBusinessModel> model) {
super(id, model);
Form<MyBusinessModel> form = new Form("form", model);
Palette<Task> palette = new Palette<Task>(.....);
form.add(palette);
form.add(new IFormValidator() {
@Override
public void Validate(Form<?> form) {
MyBusinessModel model = (MyBusinessModel) form.getModelObject();
// how to get a list of selected tasks???
List<Task> selectedTasks = model.getTasks();
}
});
}
}
Hth
Per
> I read that is a normal behavior. It's because validation occurs before
> model population.
> In that way when validation fails model won't be populated.
>
> So I would have to do something like textField.getInput() but I had a
> problem to get a model Object from a Palette.
> For example:
>
> Palette<Task> palette = new Palette<Task>(.....);
> form.add(palette);
>
> form.add(new IFormValidator() {
>
> @Override
> public void Validate(Form<?> form) {
> // how to get a list of selected tasks???
> }
> });
>
> So I made validation on "onSubmit" method of form. Now I'm fighting with
> localized message to finish.
>
> Thanks!
> Tito
>
> 2011/5/31 Per Newgro<pe...@gmx.ch>
>
>> Am 31.05.2011 15:10, schrieb Tito:
>>
>> Is this ok?
>>> I have to validate model object but it's detached when validate of form
>>> validator is called. How can I make this validation?
>>>
>>> Thanks
>>>
>>> Provide some code describing the problem please.
>> Cheers
>> Per
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org