Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7556627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:54:24+00:00 2026-05-30T11:54:24+00:00

It seems like every time I learn a new platform, I have to re-solve

  • 0

It seems like every time I learn a new platform, I have to re-solve this same old problem:
Update the choices in one drop down upon change of another dropdown, using Ajax. This time
the framework is Wicket.

I have two entities I’ll call Foo and Bar, and each Foo has a category, which is an enum internal to Foo. Also, there exists a FooDAO with overloaded find() methods: the no-arg version returns all Foo in the DB, or a version with a paramater “filter” of Type Foo that returns all Foo matching filter in non-null values.

The client wants to associate Foos to Bars when creating a new Bar, but to filter the Foos by category before adding one. So assume a handful of Foo already exist, each with a category. A user goes to the create Bar page and the section to add a new Foo: Dropdown A lists the categories, and upon choice of a category, Dropdown B is supposed to show the list of available Foo in that category, via an Ajax update. Note that is no category is selected, dropdown B should show all available Foo.

My HTML looks a little like this:

<form wicket:id="createBarForm">
<div>
    <label>Category</label>
    <select wicket:id="category">
    </select>
</div>
<div>
    <label>Available Foo(s)</label>
    <select class="xlarge" wicket:id="selectedFoo">
    </select>
</div>
<button style="float:right;">Add</button>

<!-- and more Bar related fields -->
</form>

(The button will eventually get its own id and behavior, but right now the focus is on the lists.)

Here is the Java side (in the page’s constructor method):

    createBarForm = new Form<Bar>("createBarForm",
            new CompoundPropertyModel<Bar>());

    final List<Foo> availableFoo = fooDao.find();

    final FormComponent<Foo> selectedFoo =
            new DropDownChoice<Foo>("selectedFoo", 
                    Model.of(new TechnologyFoo()), availableFoo);

    Foo.Category categoryStandin = null;

    final FormComponent<Foo.Category> fooCategory =
            new DropDownChoice<Foo.Category>
                ("fooCategory", Model.of(categoryStandin),
                        Arrays.asList(Foo.Category.values()));

    fooCategory.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = 1L;
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            // re-set the form component
            availableFoo.clear();
            ((DropDownChoice<Foo>)selectedFoo).setChoices(availableFoo);
            createBarForm.remove(selectedFoo);

            Foo.Category newSelection =
                    fooCategory.getModelObject();
            if (newSelection != null) {
                Foo filter = new Foo();
                filter.setCategory(newSelection);
                availableFoo.addAll(fooDao.find(filter));
            }
            else {
                availableFoo.addAll(fooDao.find());
            }
            // re-fresh the form component
            ((DropDownChoice<Foo>)selectedFoo).setChoices(availableFoo);
            createBarForm.add(selectedFoo);
        }
    });

    createBarForm.add(fooCategory);
    createBarForm.add(selectedFoo);

    // etc.....

I haven’t shown my logger.debug calls, but with them I am able to show that the newSelection is being captured correctly, and the DAO is returning the expected list of Foo. Also, the avaliableFoo List does contain the required values as well. However, Dropdown B always shows the full list of Foo, regardless
of the category selection.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:54:26+00:00Added an answer on May 30, 2026 at 11:54 am

    You’ve got to add your DropDowns to the AjaxRequestTarget or they wouldn’t be updated.

    as in

    target.add(selectedFoo);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like it should be something very easy to do, but every time
It seems like every time I update my provisioning profile, my xcode project still
Seriously, it seems like every time I want to make my UI elements talk
Seems like a simple problem: I have an SVN repo inside our firewall. I
Seems like manage.py test creates test database every time I run the test. Is
Seems like every C# static analyzer wants to complain when it sees a public
Seems like cuke doesn't show the full error message (at least when problem occurs
I'm starting to learn JavaScript, so far no problem but I have a hard
I have updated my code to look like this. When I run it though
Hi this question or problem i have its very hard i have search and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.