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 6714621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:31:01+00:00 2026-05-26T08:31:01+00:00

I have two dropdowns. I want to populate the second dropdown on selection of

  • 0

I have two dropdowns. I want to populate the second dropdown on selection of first dropdown.
I am using struts-dojo-tags for accomplishing this.

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
<html>
<head>
<title>Welcome</title>
<script>
</script>
<sx:head />
</head>
<body>
<h2>Struts 2 + Ajax Example 2!</h2>
<s:form name="f1">
<s:textfield name="proj" label="Project Name" />
<s:url id="url" value="/populateStates.action" />
<s:select id="id1" list="countryList"
    listKey="countryId" listValue="countryName" headerKey="0"
    headerValue="-Select-" label="Country"/>
<s:select id="id2" list="list2" listKey="stateId"
    listValue="stateName" headerKey="0" headerValue="-Select-"
    label="State" />
<sx:bind sources="id1" targets="id2" events="onchange"
    href="%{#url}" />
</s:form>
<br>
</body>
</html>

My action class has two action methods.

        public String populateCountry() throws Exception{

    list1 = new ArrayList<Country>();
    list1.add(new Country(1, "Country1"));
    list1.add(new Country(2, "Country2"));
    list1.add(new Country(3, "Country3"));

    return SUCCESS;
}

public String populateStates() throws Exception{

    System.out.println("populateStates******************"+id1);

    list2 = new ArrayList<State>();

    if (id1 != null && !id1.equals("")) 
    {   
        if(id1.equals("1"))
        {
            list2.add(new State(1, "UMB1"));
            list2.add(new State(2, "UMB2"));
            list2.add(new State(3, "UMB3"));
        }
        else if(id1.equals("2"))
        {
            list2.add(new State(4, "UMB4"));
            list2.add(new State(5, "UMB5"));
            list2.add(new State(6, "UMB6"));
        }
        else if(id1.equals("3"))
        {
            list2.add(new State(7, "UMB7"));
            list2.add(new State(8, "UMB8"));
            list2.add(new State(9, "UMB9"));
        }       
    }
    return SUCCESS;
}

First action method is called when the jsp is loaded the first time (with populated Country drop down) and second action method is called when I select a country from the Country dropdown.

Problem: States drop down is not getting populated. When I debug the code, I see that when control reaches populateStates all the variables of my Action class are reset(id1, id2, list1, list2, proj). Due to which I get an empty States dropdown. Please help me to solve this issue.

  • 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-26T08:31:01+00:00Added an answer on May 26, 2026 at 8:31 am

    I don’t think <sx:bind> does what you think it does; the target’s HTML will be replaced by what the action returns.

    You could try returning just the list of <option>s (and perhaps that’s what you’re doing), but I don’t believe it would work. (If it does, definitely follow up with your own answer.)

    I’d actually recommend using the jQuery plugin; the Dojo tags have been deprecated for some time, use a very outdated version of Dojo, and often a pain to work with.

    Another option would be to just use plain old jQuery (or library of your choice)–it’s almost always easier than implementing custom functionality via a tag library. The Ajax tag libraries are great for really simple usecases, but as soon as there’s anything custom, I’m not convinced they save much effort. YMMV.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two dropdowns and I want the second dropdown to get populated on
I have two dropdowns in html. Both dropdowns are getting data mysql first dropdown
I need to populate the dropdown and onchange of this dropdown I have to
I have two models, user & offline_user, and I want to use a dropdown
I have two dropdowns. When a user selects a value from the first one
I have two things i want to do to this input text field. <input
I have two dropdowns in my site. I want to change the number of
I have two dropdowns @using (Html.BeginForm()) { <fieldset> <legend></legend> <label>User details</label> <section> @Html.LabelFor(model =>
I have two a tags and I want to create two separate click functions
I have a navigation bar that has two dropdowns (as nested ul's). I'm trying

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.