problem is here

RadioGroup rg = new RadioGroup("choice");

you are not setting the model for the radiogroup choice so your choices go
no where

RadioGroup rg = new RadioGroup("choice", new PropertyModel(item.getModel(),
"status"));

or leave it as it is and use PropertyListView instead

-igor


On 8/29/07, Alex Pine <[EMAIL PROTECTED]> wrote:
>
> Hi all,
> I'm trying to use a Radio Choice component inside a Listview so that each
> list
> item has one RadioGroup with three choices. When the form submit button is
> pressed,
> each selected choice should set a field in the model object of each list
> item.
> The code below should explain the problem more fully:
>
>
> /*
> The ultimate goal is to set the "status" field in each Participation
> object
> in the participationList of the object below.
> */
> public class Experiment {
>
>   private String name;
>
>   private List<Participation> participationList;
>
>   /* Other fields, constructors, getters, setters, etc */
>
> }
>
>
> public class Participation {
>
>     public static final int PARTICIPATED = 1;
>     public static final int NO_SHOW = -1;
>     public static final int SHOWED = 0;
>
>     private User user;
>
>     private int status;
>
>     public Participation() {
>         status = SHOWED; // Default value
>     }
>
>     /* getters, setters, etc */
> }
>
>
> /* This is the web page that is supposed to do the setting*/
> public class ParticipationPage extends BasePage {
>
>     private static final long serialVersionUID = 1L;
>
>     @SpringBean
>     private ExperimentDAO exDAO;
>
>     private DetachableExperimentModel exModel;
>
>     public ParticipationPage(Experiment ex) {
>         exModel = new DetachableExperimentModel(ex, exDAO);
>         add(new ParticipationForm("form"));
>         exModel.detach();
>     }
>
>     class ParticipationForm extends Form {
>
>         public ParticipationForm(String id) {
>             super(id);
>             List<Participation> participationList = exModel.getEx
> ().getParticipationList();
>
>             ListView subjectListView = new ListView("list",
> participationList) {
>
>                 private static final long serialVersionUID = 1L;
>
>                 /*
>                  I imagine the correct code should be something like
> this...?
>                  */
>                 public void populateItem(final ListItem item) {
>                     Participation participation =
> (Participation)item.getModelObject();
>                     item.add(new Label("name", participation.getUser
> ().getName()));
>                     RadioGroup rg = new RadioGroup("choice");
>                     rg.add(new Radio("participated", new Model(
> Participation.PARTICIPATED)));
>                     rg.add(new Radio("no show", new Model(
> Participation.NO_SHOW)));
>                     rg.add(new Radio("showed", new Model(
> Participation.SHOWED)));
>                     item.add(rg);
>                 }
>             };
>             subjectListView.setReuseItems(true);
>             add(subjectListView);
>         }
>
>         @Override
>         protected void onSubmit() {
>
>       /*
>        * Somehow I have to set each Participation object in the user's
> participationList
>        * to the choice from corresponding the radio group.
>        */
>
>             exDAO.persistExperiment(exModel.getEx());
>             exModel.detach();
>         }
>     }
> }
>
> Does anyone know how to do this easily? I imagine it's not difficult, I
> just
> can't figure it out
> from the examples on the web.
> Thanks!
> -Alex Pine
>

Reply via email to