You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by mjop <ma...@gmail.com> on 2012/02/24 14:38:43 UTC

DropDownChoice doesn't indicating previously selected value from Model

Hello Everyone,

I'm currently using DropDownChoice in my class but it unfortunately doesn't
work properly.
When I give it model which has already set value the DropDown doesn't
indicating the selected value on the rendered page. There's still "Choose
One" option selected.
My class:

public class AddProfile<T extends Profile> extends Panel {

(...)

private final IModel<List&lt;T>> profilesListModel;

private final ChoiceRenderer<Profile> profileRenderer = new
ChoiceRenderer<Profile>(
	"name", "id");

public AddProfile(final CloudService selectedService,
			final ModalWindow modal, final Class<T> profileType) {

	super(modal.getContentId());

	profilesListModel = new LoadableDetachableModel<List&lt;T>>() {
		private static final long serialVersionUID = 7058071564604627833L;

		@Override
		protected List<T> load() {
			return profileDao.get(profileType, (User) SecurityUtils
					.getSubject().getPrincipal());

		}
	};

(...)

final WebMarkupContainer profilesListContainer = new WebMarkupContainer(
	"profilesListContainer");
profilesListContainer.setOutputMarkupPlaceholderTag(true);
add(profilesListContainer);

Form<CloudService> form = new Form<CloudService>("form");
profilesListContainer.add(form);

DropDownChoice<T> displayProfilesList = new DropDownChoice<T>(
	"displayProfilesList", new PropertyModel<T>(selectedService,
		"profile"), profilesListModel, profileRenderer);

displayProfilesList.setRequired(true);
form.add(displayProfilesList);

(...)
}

I think it can be something with the <T> generics because in the other place
in my app I use DropDownChoice with strictly specified generic like
<CloudService> and it works fine.

Any advice is welcome.
Thank You!

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/DropDownChoice-doesn-t-indicating-previously-selected-value-from-Model-tp4417203p4417203.html
Sent from the Forum for Wicket Core developers mailing list archive at Nabble.com.

Re: DropDownChoice doesn't indicating previously selected value from Model

Posted by mjop <ma...@gmail.com>.
Fact, You were right. 
It was wrong equals() and hash() methods implemented.

Thank You, Martin.

P.S. Sorry for posting it in wrong topic.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/DropDownChoice-doesn-t-indicating-previously-selected-value-from-Model-tp4417203p4417793.html
Sent from the Forum for Wicket Core developers mailing list archive at Nabble.com.

Re: DropDownChoice doesn't indicating previously selected value from Model

Posted by Martin Grigorov <mg...@apache.org>.
Check that CloudService #equals() and #hashCode() are properly implemented.

And please, ask such kind of questions in users@ mailing list.

On Fri, Feb 24, 2012 at 2:38 PM, mjop <ma...@gmail.com> wrote:
> Hello Everyone,
>
> I'm currently using DropDownChoice in my class but it unfortunately doesn't
> work properly.
> When I give it model which has already set value the DropDown doesn't
> indicating the selected value on the rendered page. There's still "Choose
> One" option selected.
> My class:
>
> public class AddProfile<T extends Profile> extends Panel {
>
> (...)
>
> private final IModel<List&lt;T>> profilesListModel;
>
> private final ChoiceRenderer<Profile> profileRenderer = new
> ChoiceRenderer<Profile>(
>        "name", "id");
>
> public AddProfile(final CloudService selectedService,
>                        final ModalWindow modal, final Class<T> profileType) {
>
>        super(modal.getContentId());
>
>        profilesListModel = new LoadableDetachableModel<List&lt;T>>() {
>                private static final long serialVersionUID = 7058071564604627833L;
>
>                @Override
>                protected List<T> load() {
>                        return profileDao.get(profileType, (User) SecurityUtils
>                                        .getSubject().getPrincipal());
>
>                }
>        };
>
> (...)
>
> final WebMarkupContainer profilesListContainer = new WebMarkupContainer(
>        "profilesListContainer");
> profilesListContainer.setOutputMarkupPlaceholderTag(true);
> add(profilesListContainer);
>
> Form<CloudService> form = new Form<CloudService>("form");
> profilesListContainer.add(form);
>
> DropDownChoice<T> displayProfilesList = new DropDownChoice<T>(
>        "displayProfilesList", new PropertyModel<T>(selectedService,
>                "profile"), profilesListModel, profileRenderer);
>
> displayProfilesList.setRequired(true);
> form.add(displayProfilesList);
>
> (...)
> }
>
> I think it can be something with the <T> generics because in the other place
> in my app I use DropDownChoice with strictly specified generic like
> <CloudService> and it works fine.
>
> Any advice is welcome.
> Thank You!
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/DropDownChoice-doesn-t-indicating-previously-selected-value-from-Model-tp4417203p4417203.html
> Sent from the Forum for Wicket Core developers mailing list archive at Nabble.com.



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com