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);              

  }

}

 

Reply via email to