You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Dane Laverty <da...@chemeketa.edu> on 2008/12/03 19:50:13 UTC
Maintain radio values on submit validation
I have a form with a list of RadioGroups, which are all required. If the
user submits the form with one or more of the RadioGroups left blank,
the validator correctly returns to form. However, when that happens, any
RadioGroups the user filled also become blank. Is there a way to
maintain the values in the correctly filled RadioGroups when the form is
submitted? The relevant code is below.
add(new ListView("questions", new PropertyModel(user, "test.questions"))
{
protected void populateItem(ListItem item) {
final Question question = (Question) item.getModelObject();
// answersRadioGroup will be a group of radio buttons -- one for
each possible answer (4, currently)
RadioGroup answersRadioGroup = new RadioGroup("answers", new
PropertyModel(question, "markedAnswerLetter"));
// This loop will generate a radio button for letters A, B, C, and D
for (char letter = 'A'; letter <= 'D'; letter++) {
final String letterAsString = letter + "";
Radio radio = new Radio(letterAsString, new
Model(letterAsString));
radio.setLabel(new
Model(question.getAnswers().get(letterAsString).toString()));
answersRadioGroup.add(radio);
}
// Ensure that each question must be answered.
answersRadioGroup.setRequired(true);
// Put the whole shebang (radio buttons + answer texts) into the
test.
item.add(answersRadioGroup);
}
}
RE: Maintain radio values on submit validation
Posted by Dane Laverty <da...@chemeketa.edu>.
That solved the problem. Thank you very much!
-----Original Message-----
From: Jeremy Thomerson [mailto:jeremy@wickettraining.com]
Sent: Wednesday, December 03, 2008 12:26 PM
To: users@wicket.apache.org
Subject: Re: Maintain radio values on submit validation
Have you tried ListView.setReuseItems(true) - I didn't look at your code
in
depth, but at a glance I think the problem is that your radios are
getting
recreated.
--
Jeremy Thomerson
http://www.wickettraining.com
On Wed, Dec 3, 2008 at 12:50 PM, Dane Laverty
<da...@chemeketa.edu>wrote:
> I have a form with a list of RadioGroups, which are all required. If
the
> user submits the form with one or more of the RadioGroups left blank,
> the validator correctly returns to form. However, when that happens,
any
> RadioGroups the user filled also become blank. Is there a way to
> maintain the values in the correctly filled RadioGroups when the form
is
> submitted? The relevant code is below.
>
>
>
> add(new ListView("questions", new PropertyModel(user,
"test.questions"))
> {
>
>
>
> protected void populateItem(ListItem item) {
>
> final Question question = (Question) item.getModelObject();
>
>
>
> // answersRadioGroup will be a group of radio buttons -- one for
> each possible answer (4, currently)
>
> RadioGroup answersRadioGroup = new RadioGroup("answers", new
> PropertyModel(question, "markedAnswerLetter"));
>
>
>
> // This loop will generate a radio button for letters A, B, C, and
D
>
>
> for (char letter = 'A'; letter <= 'D'; letter++) {
>
> final String letterAsString = letter + "";
>
> Radio radio = new Radio(letterAsString, new
> Model(letterAsString));
>
> radio.setLabel(new
> Model(question.getAnswers().get(letterAsString).toString()));
>
>
>
> answersRadioGroup.add(radio);
>
> }
>
>
>
> // Ensure that each question must be answered.
>
> answersRadioGroup.setRequired(true);
>
>
>
> // Put the whole shebang (radio buttons + answer texts) into the
> test.
>
> item.add(answersRadioGroup);
>
> }
>
> }
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Maintain radio values on submit validation
Posted by Jeremy Thomerson <je...@wickettraining.com>.
Have you tried ListView.setReuseItems(true) - I didn't look at your code in
depth, but at a glance I think the problem is that your radios are getting
recreated.
--
Jeremy Thomerson
http://www.wickettraining.com
On Wed, Dec 3, 2008 at 12:50 PM, Dane Laverty <da...@chemeketa.edu>wrote:
> I have a form with a list of RadioGroups, which are all required. If the
> user submits the form with one or more of the RadioGroups left blank,
> the validator correctly returns to form. However, when that happens, any
> RadioGroups the user filled also become blank. Is there a way to
> maintain the values in the correctly filled RadioGroups when the form is
> submitted? The relevant code is below.
>
>
>
> add(new ListView("questions", new PropertyModel(user, "test.questions"))
> {
>
>
>
> protected void populateItem(ListItem item) {
>
> final Question question = (Question) item.getModelObject();
>
>
>
> // answersRadioGroup will be a group of radio buttons -- one for
> each possible answer (4, currently)
>
> RadioGroup answersRadioGroup = new RadioGroup("answers", new
> PropertyModel(question, "markedAnswerLetter"));
>
>
>
> // This loop will generate a radio button for letters A, B, C, and D
>
>
> for (char letter = 'A'; letter <= 'D'; letter++) {
>
> final String letterAsString = letter + "";
>
> Radio radio = new Radio(letterAsString, new
> Model(letterAsString));
>
> radio.setLabel(new
> Model(question.getAnswers().get(letterAsString).toString()));
>
>
>
> answersRadioGroup.add(radio);
>
> }
>
>
>
> // Ensure that each question must be answered.
>
> answersRadioGroup.setRequired(true);
>
>
>
> // Put the whole shebang (radio buttons + answer texts) into the
> test.
>
> item.add(answersRadioGroup);
>
> }
>
> }
>
>
>
>