views:

49

answers:

2

Hey all,

Please allow me to preface this by saying I'm pretty much brand new to java web development so I hope I'm explaining this problem correctly.

I've inherited a wicket website from a fellow who has left for greener pastures and there has been a request to ask new users to include their race and ehthnicity upon registration to the website. So I've added the appropriate questions to the page... so far so good.

The problem I'm getting now is that when I submit the page the new values don't seem to get updated. I'm going to post the code here for the racial question but the ethnicity question is almost identical. It may be important to note that a user should be able to select more than one race or no races at all when registration occurs.

My relevant mark-up:

<span wicket:id="selectOneOrMoreRaces">Select one or more races to indicate what you consider yourself to be.</span>
<br />
<span class="field" wicket:id="races">
  <span wicket:id="races">
    <input wicket:id="races.value" type="checkbox" />
    <span wicket:id="racDesc" style="font-weight:normal;">Race Text</span>
    <br />
  </span>
</span>

Here's the bit of code for that page:

String raceQuestion = fhDAO.getRaceQuestion();
Label selectOneOrMoreRacesLabel = new Label("selectOneOrMoreRaces", new Model(raceQuestion));
add(selectOneOrMoreRacesLabel);

CheckGroup racesCheckGroup = new CheckGroup("races");
add(racesCheckGroup);
ListView races = new ListView("races", fhDAO.getRaceAnswers())
{
  protected void populateItem(ListItem item)
  {
    RaceAnswer access = (RaceAnswer)item.getModelObject();
    CheckBox chk = new CheckBox("races.value", new Model(access.getValue()));
    item.add(chk);
    item.add(new Label("racDesc", access.getDescription()));
  }
};
racesCheckGroup.add(races);

Here's the model for the RaceAnswers:

public class RaceAnswer implements Serializable
{
    private String _description;
    private String _value;

    public RaceAnswer(String description, String value)
    {
        _description = description;
        _value = value;
    }

    public String getDescription()
    {
        return _description;
    }

    public String getValue()
    {
        return _value;
    }
}

And finally, the relevant code for my races property in my user class:

private ArrayList<RaceAnswer> race;

public ArrayList<RaceAnswer> getRaces()
{
  return race;
}

public void setRaces(ArrayList<RaceAnswer> races)
{
  race = races;
}

Thanks in advance for any assistance that can be rendered.

-Sonny

A: 

I hate to ask for more code as you've already posted quite a bit, but the difficulties are most commonly in how the models are attached to the form, and the form itself isn't in your posted code, so posting a bit more of the form code might help diagnose.

Meanwhile, you may have already seen it to get this far, but there's a simple example of CheckGroup usage in a form that might be helpful among the examples at wicketstuff 1.3 examples or wicketstuff 1.4 examples.

Don Roby
+1  A: 

I finally fixed it. There was a couple of problems...

First, I should have been using Check and not CheckBox. This change exposed the fact that my collections were coming back as null from my model and not just empty (but instantiated) collections as I was expecting.

All good now!

Sonny Boy