You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Ray Weidner <ra...@gmail.com> on 2010/04/19 17:29:31 UTC
problem populating ListMultipleChoice selection model
Hi All,
I'm trying to do something pretty simple: create a choice list with
multi-select, which I iterate through upon clicking a button.
Unfortunately, it looks like my selections aren't being recorded in the
model that's supposed to receive them. Here's what the pertinent code looks
like:
- Java:
public EditIssuePage extends WebPage {
// I've tried removing the 'transient' keyword, but that doesn't change
anything
transient private Set <Party> selectedParties = new HashMap <Party> ();
...
public EditIssuePage () {
...
Form form = new Form ("editIssueForm");
add (form);
...
ListMultipleChoice <Party> partyChoice = new ListMultipleChoice
<Party> (
"parties",
new PropertyModel (this, "selectedParties"),
new LoadableDetachableModel <List <Party>> () {
@Override
public List <Party> load () {
return new Vector <Party> (retrieveAllPartiesFromDAO ());
}
},
new IChoiceRenderer <Party> () {
public Object getDisplayValue (Party object) {
return object.getFullName ();
}
public String getIdValue (Party object, int index) {
return object.getId ();
}
}
);
Button addPartiesButton = new Button ("addPartiesButton") {
@Override
public void onSubmit () {
logger.debug ("Number of selected parties: " +
selectedParties.size ()); // always reporting zero!
for (Party selectedParty : selectedParties) {
...
}
}
};
form.add (partyChoice);
form.add (addPartiesButton);
}
private Set <Party> retrieveAllPartiesFromDAO () {
// does what it sounds like
}
}
- HTML: (My memory is a bit hazy here; I don't have any of this code in
front of me as I write this)
...
<select multiple wicket:id="parties">
<option>[A party should be here]</option>
</select>
<submit wicket:id="addPartiesButton" name="Add Selected Parties"/>
...
The page renders fine, with all Party objects listed for selection. But
when I select one or more of the rows and click the button, the log message
I see is "Number of selected parties: 0", no matter what. I have very
similar logic working on another page, so I'm pretty confused about what's
the problem here. All advice is much appreciated.
Thanks,
Ray Weidner
Re: problem populating ListMultipleChoice selection model
Posted by Ray Weidner <ra...@gmail.com>.
Hi Moez,
I'll give that a try when I have the code in front of me. But I'd be
surprised if that works, because I am doing precisely the same thing on
another page, including using a Set for the selected item model. In that
instance, there's no problem.
On Mon, Apr 19, 2010 at 11:55 AM, moèz ben rhouma
<be...@gmail.com>wrote:
> Try to change the type of selectedParties from set to List selectedParties
> = new ArrayList();
>
> 2010/4/19 Ray Weidner <ra...@gmail.com>
>
> > Hi All,
> >
> > I'm trying to do something pretty simple: create a choice list with
> > multi-select, which I iterate through upon clicking a button.
> > Unfortunately, it looks like my selections aren't being recorded in the
> > model that's supposed to receive them. Here's what the pertinent code
> > looks
> > like:
> >
> > - Java:
> >
> > public EditIssuePage extends WebPage {
> > // I've tried removing the 'transient' keyword, but that doesn't change
> > anything
> > transient private Set <Party> selectedParties = new HashMap <Party> ();
> > ...
> > public EditIssuePage () {
> > ...
> > Form form = new Form ("editIssueForm");
> > add (form);
> > ...
> > ListMultipleChoice <Party> partyChoice = new ListMultipleChoice
> > <Party> (
> > "parties",
> > new PropertyModel (this, "selectedParties"),
> > new LoadableDetachableModel <List <Party>> () {
> > @Override
> > public List <Party> load () {
> > return new Vector <Party> (retrieveAllPartiesFromDAO
> ());
> > }
> > },
> > new IChoiceRenderer <Party> () {
> > public Object getDisplayValue (Party object) {
> > return object.getFullName ();
> > }
> >
> > public String getIdValue (Party object, int index) {
> > return object.getId ();
> > }
> > }
> > );
> > Button addPartiesButton = new Button ("addPartiesButton") {
> > @Override
> > public void onSubmit () {
> > logger.debug ("Number of selected parties: " +
> > selectedParties.size ()); // always reporting zero!
> > for (Party selectedParty : selectedParties) {
> > ...
> > }
> > }
> > };
> > form.add (partyChoice);
> > form.add (addPartiesButton);
> > }
> >
> > private Set <Party> retrieveAllPartiesFromDAO () {
> > // does what it sounds like
> > }
> > }
> >
> > - HTML: (My memory is a bit hazy here; I don't have any of this code in
> > front of me as I write this)
> >
> > ...
> > <select multiple wicket:id="parties">
> > <option>[A party should be here]</option>
> > </select>
> > <submit wicket:id="addPartiesButton" name="Add Selected Parties"/>
> > ...
> >
> > The page renders fine, with all Party objects listed for selection. But
> > when I select one or more of the rows and click the button, the log
> message
> > I see is "Number of selected parties: 0", no matter what. I have very
> > similar logic working on another page, so I'm pretty confused about
> what's
> > the problem here. All advice is much appreciated.
> >
> > Thanks,
> > Ray Weidner
> >
>
Re: problem populating ListMultipleChoice selection model
Posted by moèz ben rhouma <be...@gmail.com>.
Try to change the type of selectedParties from set to List selectedParties
= new ArrayList();
2010/4/19 Ray Weidner <ra...@gmail.com>
> Hi All,
>
> I'm trying to do something pretty simple: create a choice list with
> multi-select, which I iterate through upon clicking a button.
> Unfortunately, it looks like my selections aren't being recorded in the
> model that's supposed to receive them. Here's what the pertinent code
> looks
> like:
>
> - Java:
>
> public EditIssuePage extends WebPage {
> // I've tried removing the 'transient' keyword, but that doesn't change
> anything
> transient private Set <Party> selectedParties = new HashMap <Party> ();
> ...
> public EditIssuePage () {
> ...
> Form form = new Form ("editIssueForm");
> add (form);
> ...
> ListMultipleChoice <Party> partyChoice = new ListMultipleChoice
> <Party> (
> "parties",
> new PropertyModel (this, "selectedParties"),
> new LoadableDetachableModel <List <Party>> () {
> @Override
> public List <Party> load () {
> return new Vector <Party> (retrieveAllPartiesFromDAO ());
> }
> },
> new IChoiceRenderer <Party> () {
> public Object getDisplayValue (Party object) {
> return object.getFullName ();
> }
>
> public String getIdValue (Party object, int index) {
> return object.getId ();
> }
> }
> );
> Button addPartiesButton = new Button ("addPartiesButton") {
> @Override
> public void onSubmit () {
> logger.debug ("Number of selected parties: " +
> selectedParties.size ()); // always reporting zero!
> for (Party selectedParty : selectedParties) {
> ...
> }
> }
> };
> form.add (partyChoice);
> form.add (addPartiesButton);
> }
>
> private Set <Party> retrieveAllPartiesFromDAO () {
> // does what it sounds like
> }
> }
>
> - HTML: (My memory is a bit hazy here; I don't have any of this code in
> front of me as I write this)
>
> ...
> <select multiple wicket:id="parties">
> <option>[A party should be here]</option>
> </select>
> <submit wicket:id="addPartiesButton" name="Add Selected Parties"/>
> ...
>
> The page renders fine, with all Party objects listed for selection. But
> when I select one or more of the rows and click the button, the log message
> I see is "Number of selected parties: 0", no matter what. I have very
> similar logic working on another page, so I'm pretty confused about what's
> the problem here. All advice is much appreciated.
>
> Thanks,
> Ray Weidner
>