You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Linda van der Pal <lv...@heritageagenturen.nl> on 2009/08/19 16:54:20 UTC

How do I get my DropDownChoice to refresh the list of choices with Ajax?

I have a page with a dropdown list on it with authors. If I enter a new 
book I want my fields to be filled based on the ISBN. This works just 
fine. But now I want those fields to be filled with data  I collect from 
the internet, meaning that it isn't always already in my database, and 
therefor the author might not yet be in the list. I have already decided 
to save the new author so I can select it in the list, but the list 
isn't updated, and I can't figure out how to get it to update.

Here are some pieces of code I think are relevant:

This is how I create the authorfield:

authorField = new MultiSelectFieldSwitchPanel("authors", dataRetriever.fetchAuthors(), new PropertyModel(this, "book.authors"));


dataRetriever.fetchAuthors return a List<Author>

Here's the constructor of MultiSelectFieldSwitchPanel which extends 
FormComponentPanel:

public MultiSelectFieldSwitchPanel(final String id, final List<? extends DomainObject> authors, final IModel<List<Author>> model) {
    super(id, model);
    lmc = new ListMultipleChoice("selectField", new PropertyModel<List<Author>>(this, "selectedObjects"), 
                                 authors, new ChoiceRenderer<DomainObject>("name", "id"));
    init(lmc);
}

The init method adds a link to swap the lmc for a textfield where new 
authors can be entered, which is not really relevant in this case.

I have of course already added authorField to the AjaxRequestTarget in 
the behavior that is triggered by updating the ISBN.

Regards,
Linda

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How do I get my DropDownChoice to refresh the list of choices with Ajax?

Posted by Igor Vaynberg <ig...@gmail.com>.
http://wicketstuff.org/wicket/ajax/choice

-igor

On Wed, Aug 19, 2009 at 7:54 AM, Linda van der
Pal<lv...@heritageagenturen.nl> wrote:
> I have a page with a dropdown list on it with authors. If I enter a new book
> I want my fields to be filled based on the ISBN. This works just fine. But
> now I want those fields to be filled with data  I collect from the internet,
> meaning that it isn't always already in my database, and therefor the author
> might not yet be in the list. I have already decided to save the new author
> so I can select it in the list, but the list isn't updated, and I can't
> figure out how to get it to update.
>
> Here are some pieces of code I think are relevant:
>
> This is how I create the authorfield:
>
> authorField = new MultiSelectFieldSwitchPanel("authors",
> dataRetriever.fetchAuthors(), new PropertyModel(this, "book.authors"));
>
>
> dataRetriever.fetchAuthors return a List<Author>
>
> Here's the constructor of MultiSelectFieldSwitchPanel which extends
> FormComponentPanel:
>
> public MultiSelectFieldSwitchPanel(final String id, final List<? extends
> DomainObject> authors, final IModel<List<Author>> model) {
>   super(id, model);
>   lmc = new ListMultipleChoice("selectField", new
> PropertyModel<List<Author>>(this, "selectedObjects"),
>          authors, new ChoiceRenderer<DomainObject>("name", "id"));
>   init(lmc);
> }
>
> The init method adds a link to swap the lmc for a textfield where new
> authors can be entered, which is not really relevant in this case.
>
> I have of course already added authorField to the AjaxRequestTarget in the
> behavior that is triggered by updating the ISBN.
>
> Regards,
> Linda
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How do I get my DropDownChoice to refresh the list of choices with Ajax?

Posted by Linda van der Pal <lv...@heritageagenturen.nl>.
Doh, I should have thought of that myself. That'll teach me to send a 
question at the end of the day. Thanks for taking the time to answer my 
question, Bas and Igor.

Regards,
Linda

Bas Gooren wrote:
> Linda,
>
> Without looking at your question very long I noticed that you supply 
> your component with a static List<Author>.
>
> This means that this list is only retrieved once (at initialization). 
> It sounds like you want it to be refreshed when other components 
> change their input. This would mean you need to supply a Model which 
> returns a List<Author>; That way when you re-render the component 
> through AJAX, it reloads the list of authors.
>
> Regards,
>
> Bas
>
> ----- Original Message ----- From: "Linda van der Pal" 
> <lv...@heritageagenturen.nl>
> To: <us...@wicket.apache.org>
> Sent: Wednesday, August 19, 2009 4:54 PM
> Subject: How do I get my DropDownChoice to refresh the list of choices 
> with Ajax?
>
>
>> I have a page with a dropdown list on it with authors. If I enter a 
>> new book I want my fields to be filled based on the ISBN. This works 
>> just fine. But now I want those fields to be filled with data  I 
>> collect from the internet, meaning that it isn't always already in my 
>> database, and therefor the author might not yet be in the list. I 
>> have already decided to save the new author so I can select it in the 
>> list, but the list isn't updated, and I can't figure out how to get 
>> it to update.
>>
>> Here are some pieces of code I think are relevant:
>>
>> This is how I create the authorfield:
>>
>> authorField = new MultiSelectFieldSwitchPanel("authors", 
>> dataRetriever.fetchAuthors(), new PropertyModel(this, "book.authors"));
>>
>>
>> dataRetriever.fetchAuthors return a List<Author>
>>
>> Here's the constructor of MultiSelectFieldSwitchPanel which extends 
>> FormComponentPanel:
>>
>> public MultiSelectFieldSwitchPanel(final String id, final List<? 
>> extends DomainObject> authors, final IModel<List<Author>> model) {
>>    super(id, model);
>>    lmc = new ListMultipleChoice("selectField", new 
>> PropertyModel<List<Author>>(this, "selectedObjects"), authors, new 
>> ChoiceRenderer<DomainObject>("name", "id"));
>>    init(lmc);
>> }
>>
>> The init method adds a link to swap the lmc for a textfield where new 
>> authors can be entered, which is not really relevant in this case.
>>
>> I have of course already added authorField to the AjaxRequestTarget 
>> in the behavior that is triggered by updating the ISBN.
>>
>> Regards,
>> Linda
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com 
> Version: 8.5.409 / Virus Database: 270.13.61/2314 - Release Date: 08/19/09 18:06:00
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How do I get my DropDownChoice to refresh the list of choices with Ajax?

Posted by Bas Gooren <ba...@iswd.nl>.
Linda,

Without looking at your question very long I noticed that you supply your 
component with a static List<Author>.

This means that this list is only retrieved once (at initialization). It 
sounds like you want it to be refreshed when other components change their 
input. This would mean you need to supply a Model which returns a 
List<Author>; That way when you re-render the component through AJAX, it 
reloads the list of authors.

Regards,

Bas

----- Original Message ----- 
From: "Linda van der Pal" <lv...@heritageagenturen.nl>
To: <us...@wicket.apache.org>
Sent: Wednesday, August 19, 2009 4:54 PM
Subject: How do I get my DropDownChoice to refresh the list of choices with 
Ajax?


>I have a page with a dropdown list on it with authors. If I enter a new 
>book I want my fields to be filled based on the ISBN. This works just fine. 
>But now I want those fields to be filled with data  I collect from the 
>internet, meaning that it isn't always already in my database, and therefor 
>the author might not yet be in the list. I have already decided to save the 
>new author so I can select it in the list, but the list isn't updated, and 
>I can't figure out how to get it to update.
>
> Here are some pieces of code I think are relevant:
>
> This is how I create the authorfield:
>
> authorField = new MultiSelectFieldSwitchPanel("authors", 
> dataRetriever.fetchAuthors(), new PropertyModel(this, "book.authors"));
>
>
> dataRetriever.fetchAuthors return a List<Author>
>
> Here's the constructor of MultiSelectFieldSwitchPanel which extends 
> FormComponentPanel:
>
> public MultiSelectFieldSwitchPanel(final String id, final List<? extends 
> DomainObject> authors, final IModel<List<Author>> model) {
>    super(id, model);
>    lmc = new ListMultipleChoice("selectField", new 
> PropertyModel<List<Author>>(this, "selectedObjects"), authors, new 
> ChoiceRenderer<DomainObject>("name", "id"));
>    init(lmc);
> }
>
> The init method adds a link to swap the lmc for a textfield where new 
> authors can be entered, which is not really relevant in this case.
>
> I have of course already added authorField to the AjaxRequestTarget in the 
> behavior that is triggered by updating the ISBN.
>
> Regards,
> Linda
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org