Struts 2 AJAX Autocomplete dropdown example

I started playing with struts 2.0.14 showcase application and thought of extracting a simple AJAX Autocomplete dropdown example from it.
In this example I am trying to create a autocomplete textbox and when you select one value from this autocomplete drop down the other will populate accordingly.

This post is for developers who are new to Struts 2.

This example uses

- Struts 2.0.14 - Download Struts
- apache-tomcat-6.0.18 - Download Tomcat
- java version "1.6.0_10"
- freemarker template (2.3.8) for the second dropdown.

You can use this example as is or play around with it based on your need.

index.jsp :

This page redirects the request to the demo page where autocomplete text box is diplayed.

<%@ taglib prefix="s" uri="/struts-tags" %>


This page contains the core of this example, the Struts tags for Autocomplete.

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<s:head theme="ajax"/>
<s:url id="detailUrl" action="DetailResponse"/>

Link two autocompleter elements. When the selected value in 'Autocompleter 1' changes,
the available values in 'Autocompleter 2' will change also.
<form id="selectForm">
<p>Autocompleter 1 <s:autocompleter theme="simple" name="select" list="selectList" value="Colors" notifyTopics="/Changed" forceValidOption="true" id="sel"/></p>
Autocompleter 2 <s:autocompleter theme="ajax" href="%{#detailUrl}" autoComplete="false" formId="selectForm" listenTopics="/Changed" forceValidOption="true" id="ops"/>


This is Freemarker template to render the second drop down, which is populated based on selection in first autocomplete drop down.

<#list options as option>


This action class is to populate values in the first autocomplete drop down.


package ajaxdemo.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class ListingAction extends ActionSupport {
private List selectList = null;

public String execute() throws Exception {
selectList = new ArrayList();
return SUCCESS;

public List getSelectList() {
return selectList;

public void setSelectList(List selectList) {
this.selectList = selectList;


This is a action class to populate the second autocomplete drop down based on selection value in first drop down.

package ajaxdemo.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class DetailAction extends ActionSupport {
private String select;
private List options = new ArrayList();

private static final long serialVersionUID = -8481638176160014396L;

public String execute() throws Exception {
if ("Fruits".equalsIgnoreCase(select)) {
} else if ("Colors".equalsIgnoreCase(select)) {
return SUCCESS;

public String getSelect() {
return select;

public void setSelect(String select) { = select;

public List getOptions() {
return options;


Struts config file for action mappings.


<?xml version="1.0" encoding="UTF-8" ?>

"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

<package name="demo" extends="struts-default">
<action name="ShowDemo" class="ajaxdemo.action.ListingAction">
<action name="DetailResponse" class="ajaxdemo.action.DetailAction">
<result type="freemarker">/options.ftl</result>


The application deployment descriptor.


<web-app version="2.4" xmlns=""


Go the URL http://localhost:8080/ajaxdemo/ in your favorite web browser. The page should look like this.

Web application directory Structure
This is how the application war directory structure should look like.


Here are the list of jar files you need to have in your application WEB-INF/lib dir.



Download ajaxdemo.war here

struts form, struts 2 ajax autocomplete drop down code example, Struts2 ajax autocomplete tutorial with sample code, struts 2 ajax auto complete drop down code download, struts training, apache struts training online

33 Post Comment

Dave said...

Hey, Thanks for this handy example. I just tried running the same code using Struts 2.1.8 dependancies and got this error. Do you have some clue?

SEVERE: Exception starting filter struts2
Class: com.opensymphony.xwork2.spring.SpringObjectFactory
Method: getClassInstance
Line: 209 - com/opensymphony/xwork2/spring/
at org.apache.struts2.dispatcher.Dispatcher.init(
at org.apache.struts2.dispatcher.FilterDispatcher.i n it(
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(
at org.apache.catalina.core.ApplicationFilterConfig.<init>(
at org.apache.catalina.core.StandardContext.filterStart(
at org.apache.catalina.core.StandardContext.start(
at org.apache.catalina.core.ContainerBase.addChildInternal(
at org.apache.catalina.core.ContainerBase.addChild(
at org.apache.catalina.core.StandardHost.addChild(
at org.apache.catalina.startup.HostConfig.deployWAR(
at org.apache.catalina.startup.HostConfig.deployWARs(
at org.apache.catalina.startup.HostConfig.deployApps(
at org.apache.catalina.startup.HostConfig.start(
at org.apache.catalina.startup.HostConfig.lifecycleEvent(
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(
at org.apache.catalina.core.ContainerBase.start(
at org.apache.catalina.core.StandardHost.start(
at org.apache.catalina.core.ContainerBase.start(
at org.apache.catalina.core.StandardEngine.start(
at org.apache.catalina.core.StandardService.start(
at org.apache.catalina.core.StandardServer.start(
at org.apache.catalina.startup.Catalina.start(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(
at org.apache.catalina.startup.Bootstrap.main(
Caused by: java.lang.NullPointerException
at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyResultType(
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addResultTypes(
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(
at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(
at it_PreloadConfiguration(
at it(
... 28 more
Oct 29, 2009 5:43:17 PM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart

Software Wikipedia said...

@Dave - I have not tested this example on Struts 2.1.8 and from my experience I can say it will NOT work as it is.

1. I tried running this directly on struts 2.1.8 dependencies and I can see there are much more errors to fix.

2. There are some tag lib changes in Struts 2.1.8 which needs to be incorporated in the JSPs.

3. Will update this post if I am able to get a Struts 2.1.8 version for same example.

BTW, on a sidenote, I don't really understand why Struts 2.1.8 is not easily backward compatible with 2.0.14?

Software Wikipedia said...

Update 1: I tried checking the showcase application for struts 2.1.8 and it seems this example doesn't work on showcase application either. So there must be something broken in 2.1.8

Shashi said...

Hi ,
I worked with this code , it works successfully it shows the value into the 1st dropdown list .
we are able to select the value from 1st dropdown list but second dropdown list is empty....
could you tell me reson....

Anonymous said...


I want to populate table from database using autocompleter value. any help will be appreciated.

Java said...


Java said...

how to implement this in Struts 2.2 or struts 2.3...we dont have struts' autocompleter tag..we have struts' dojo tag..
do anyone know anything about this???

Anonymous said...

above code in not working

Anonymous said...

No one would like to be forced to help make their exercising tools a
part with the room furnishings.

Feel free to visit my web-site :: bowflex selecttech 552 adjustable dumbbells pair

Anonymous said...

That you are accomplishing exercises and also your body completely requirements calories.

Also visit my weblog Góra strony

Anonymous said...

The inside workouts tend to be more strength education that

Here is my blog :: bowflex dumbbells

Anonymous said...

After you use air as your resistance mechanism you increase or decrease the resistance according for your personal efforts, which means you have
got quite a bit considerably less chance of overdoing it
or injuring on your own.

Have a look at my blog; bowflex selecttech 552 dumbbells used

Anonymous said...

my code is working but second drop down don't work..
can u tell me the reason??

groovy said...

Chained autocomplete would be very cool as an example

Anonymous said...

nike free, kate spade outlet, prada handbags, coach factory outlet, oakley sunglasses, true religion, coach purses, oakley sunglasses, louboutin, michael kors outlet, ray ban, louis vuitton outlet online, jordan shoes, coach factory, longchamp outlet, ray ban sunglasses, louis vuitton handbags, coach outlet, nike shoes, true religion outlet, tiffany and co, michael kors outlet, true religion jeans, oakley sunglasses, gucci outlet, louboutin, chanel handbags, polo ralph lauren outlet, oakley sunglasses, ray ban sunglasses, toms shoes, oakley sunglasses, tory burch outlet, air max, coach outlet store, nike air max, polo ralph lauren, burberry outlet online, burberry outlet online

Anonymous said...

air max, nfl jerseys, nike free, marc jacobs, chi flat iron, air max, hogan, air jordan, nike free, mcm handbags, new balance shoes, ghd, mont blanc, louis vuitton, yoga pants, louis vuitton, bottega, karen millen, longchamp, juicy couture outlet, louboutin, abercrombie and fitch, rolex watches, nike air max, ralph lauren, reebok outlet, birkin bag, ralph lauren, nike air max, vans, lancel, north face outlet, insanity, supra shoes, lululemon, ferragamo shoes, beats by dre, timberland, hollister, converse shoes, mulberry

pai young said...

Shame uttered after, his face flushed pity if the text is difficult to maintain a normal state of mind is no longer North Face Fleece Clearance under Cheap North Face Fleece the watchful eyes and ran away like jumped out of the ring disappeared in the crowd.

A corner of the edge North Face Fleece Jackets of the grandstand, a fluttering white woman body trembling, peerless extremely pale face at this time, perhaps, ultimately this is a dream, right Goodbye North Face Fleece Clearance language under North Face Fleece Sale pale beauty, beautiful eyes of sadness in two lines of tears shed down, long-sleeved Qingbai, already turned quietly away.

These certainly do not North Face Fleece Sale know that he was also fascinated on a pair of soft, without the slightest North Face Fleece Jackets relenting meaning. Whining. Originally indulge them if unfortunately the referee gave the Qing Ke Wen suddenly woke up, I do not know where's an effort to one open.

pai young said...

Pas cher pas de mots ont immédiatement pris le téléphone et moncler pas cher composer le moncler pas cher numéro de la maison pas cher. Non loin derrière celle de la moncler pas cher brique suivante est cachée moncler pas cher Qui ne doudoune moncler pas cher connaît pas un héros sur le champ moncler pas cher de bataille est toujours le premier à mourir. Porte céleste. moncler pas cher Homme émacié dit que deux mots, moncler pas cheroncle Sept frère envoyé, oncle Sept en ce moment à travers le téléphone avec l'oncle Sept, il a déclaré que le jour de la porte, l'autre moncler soldes n'a pas dit, j'ai vu le gars a pris Allen l'appel téléphonique . moncler pas cher Qu'est-ce que vous avez dit.

pae young said...

I get knifed you. cheap barbour international jackets cheap glanced at mens barbour jacket sale the Arab East, saw to his face pockmarked, mens barbour jacket sale pointing cheap womens barbour jacket to cheap mud horse, I was gantry East Tangtang Zhu Adon, I tell mens barbour jacket sale you, and quickly put a sale, otherwise mouthful of yellow teeth, mens barbour jacket sale hair, barbour jacket sale head left with a wisp, just another ugly enough.

Guo Guo said...

louis vuitton handbags
coach handbags
coach outlet online
polo ralph lauren outlet
salvatore ferragamo
oakley sunglasses
michael kors outlet online
true religion outlet
swarovski jewelry
oakley outlet
michael kors handbags
asics running shoes
air jordan 6
ray ban sunglasses online
celine outlet online
tory burch sandals
burberry handbags
cheap mlb jerseys
ray ban sunglasses
beats studio
calvin klein outlet
timberland boots
ray ban outlet
louis vuitton
nhl jerseys
discount oakley sunglasses
cheap ray ban sunglasses
coach outlet store online
chanel outlet
puma sneakers
lebron shoes
air jordan gamma blue
rolex watches
michael kors outlet online
tods shoes
tiffany and co
tiffany and co
air force 1 shoes
iphone 6 cases

papa young said...

Polo Ralph Lauren Pas Cher jump Polo Ralph Lauren Pas Cher jump pas cher, jouer ensemble et nouveau champion. Maintenant, vous regardez la télévision Polo Ralph Lauren Pas Cher est un Ralph Lauren Soldes espace de rêve pour vos rêves diffusées match de boxe. Nos meilleurs joueurs contestent la Polo Ralph Lauren Pas Cher vingt champion force pas cher. Titre si il peut obtenir un champion du Dream Cup il.

Wenhao Guo said...

herve leger
cheap jordans
kobe bryants shoes 2015
adidas shoes
ugg boots
oakley sunglasses
michael kors handbags
cheap oakley sunglasses
celine handbags
vans shoes
mbt shoes
air jordan shoes
lacoste polo shirts
new balance shoes
new england patriots jerseys
converse outlet
lacoste shoes
coach outlet store
miami heat jersey
babyliss hair dryer
oakley sunglasses
michael kors outlet online sale
ray ban sunglasses
swarovski uk
cheap snapbacks
longchamp outlet
cartier watches
coach outlet online
supra shoes
coach outlet
christian louboutin shoes
ferragamo belts
nike running shoes
louis vuitton outlet stores
ghd hair straighteners
mulberry outlet
dansko outlet
nhl jerseys wholesale
true religion outlet
tiffany jewelry

Wei Chen said...

moncler coats
prom dresses
cheap football shirts
hermes bags
nike free,nike free run,free running,free run,nike running
phil mcconkey jersey,odell beckham jr jersey,michael strahan jersey,chris snee jersey,larry donnell jersey,peyton hillis jersey,carl banks jersey,lawrence taylor jersey,phil mcconkey jersey,justin tuck jersey,michael boley jersey,chase blackburn jersey
swarovski uk
barcelona soccer jersey
cleveland cavaliers jersey
nike free
chelsea football shirts
camisetas futbol baratas
nike air max 2014
swarovski crystal
the north face clearance
kate spade outlet
manchester united football shirts
chanel handbags
chiefs jersey
arizona cardinals jerseys
monster beats
ysl outlet
stephen curry jersey
nike trainers uk
football shirts

Junda Xu said...

20150718 junda
polo ralph lauren
chanel online shop
coach factory outlet
soccer shoes
michael kors
louis vuitton sacs
nike blazer high
cheap snapbacks hats
tory burch outlet online
cheap jordans free shipping
tory burch handbags
michael kors outlet
ed hardy clothing outlet
kate spade bags
replica watches for sale
michael kors outlet
burberry handbags
ralph lauren polo shirts
oakley sunglasses
michael kors handbags
pandora bracelets
ray ban outlet
michael kors purse
michael kors handbags
longchamp pliage pas cher
cheap oakleys
polo outlet
ed hardy uk
ray ban sunglasses
christian louboutin
pandora charms
cheap oakley sunglasses
mcm backpack
pandora charms
football jerseys
ed hardy clothing uk
soccer jerseys for sale
chanel bags
louis vuitton borse

Meiqing Xu said...

jordan 3
oakley sunglasses,oakley vault,prescription sunglasses,polarized sunglasses,aviator sunglasses,spy sunglasses,oakleys,oakley canada,cheap oakley sunglasses,oakley frogskins,oakley holbrook,cheap sunglasses,wayfarer sunglasses,oakley standard issue,fake oakleys,oakley glasses,,oakley prescription glasses,oakley goggles,sunglasses for men,oakley gascan,oakley store,oakleys sunglasses
michael kors outlet online
coach factory outlet
ugg slippers
oakley sunglasses sale
coach factory outlet
sac longchamp pas cher
polo ralph lauren
ugg sale
michael kors outlet
mont blanc
michael kors
air jordan 13
giuseppe zanotti
louis vuitton outlet stores
mcm handbags
toms outlet
louis vuitton
cheap ugg boots
louis vuitton outlet
michael kors outlet
louis vuitton handbags
lebron james shoes 2015
instyler max
jordan retro
ghd hair straighteners
louis vuitton

Hyabe Ibbe said...

17jordan 6s
kate spade handbags
michael kors handbags outlet stores
mbt outlet
vans shoes clearance
coach sunglasses
coach outlet online
under armour sale
salvatore ferragamo
columbia outlet store
columbia sportswear outlet
fitflop outlet online
canada goose for sale
coach factory outlet
kobe bryant shoes
kids north face jackets
air jordan 6
polo outlet
nike shoes
coach shoes
kate spade sale
boys north face jackets
hermes bag
canada goose jacket outlet
michael kors sale
nike online
nike shoes
michael kors outlet 70% off
north face sale
north face kids
cheap gucci shoes
cheap gucci shoes
michael kors outlet online
michael kors handbags
salvatore ferragamo shoes
tods outlet
ugg boots sale
nike air max 2015
fitflops clearance
new balance shoes
uggs sale
christian louboutin shoes

风骚达哥 said...

20151012 junda

风骚达哥 said...

20151012 junda
michael kors outlet
ugg outlet store
Coach Factory Outlet Private Sale
michael kors handbags
Ugg Boots,Ugg Boots Outlet,Ugg Outlet,Cheap Uggs,Uggs On Sale,Ugg Boots Clearance,Uggs For Women
louis vuitton outlet
Louis Vuitton Bags On Sale
air max 95,nike golf,nike janoski,air max 1,nike canada,nike plus,nike shox,nike factory store
ugg boots
cheap uggs
Coach Factory Outlet Private Sale
ugg boots sale
coach outlet
Louboutin Red Bottoms Shoes Outlet
Christian Louis Vuitton Red Bottoms
Louis Vuitton Bags On Sale
Michael Kors Outlet Sale Clearance
Abercrombie & Fitch Factory Outlet
ugg boots australia
Lebron James Basketball Shoes Sale
coach factory outlet
michael kors bags
ugg boots sale
tory burch outlet
Gucci Outlet Online Sale
michael kors handbag
air max 90
Michael Kors Outlet Online Mall
timberland boots for women
coach outlet online

Minko Chen said...

north face outlet,
mcm backpack,
michael kors outlet online,
ugg outlet online,
michael kors wallet sale,
swarovski crystal,
cowboys jerseys,
mbt shoes outlet,
michael kors outlet,
iphone 6 cases,
ralph lauren outlet,
oakley sunglasses wholesale,
hollister shirts,
asics,asics israel,asics shoes,asics running shoes,asics israel,asics gel,asics running,asics gel nimbus,asics gel kayano
hermes outlet store,
los angeles clippers jerseys,
nike free run uk,
colts jerseys,
baltimore ravens jerseys,
hogan,hogan outlet,scarpe hogan,hogan sito ufficiale,hogan interactive
louis vuitton,borse louis vuitton,louis vuitton sito ufficiale,louis vuitton outlet

ninest123 Ninest said...

ninest123 11.24
louboutin uk, nike outlet, louis vuitton handbags, michael kors outlet online, nike air max, ralph lauren polo, longchamp bags, replica watches, christian louboutin, uggs outlet, burberry factory outlet, tiffany jewelry, uggs on sale, louis vuitton outlet, michael kors handbags, burberry outlet, tory burch outlet, ray ban sunglasses, oakley sunglasses, louis vuitton outlet, longchamp outlet, oakley sunglasses, ray ban sunglasses, ray ban sunglasses, oakley sunglasses, gucci handbags, oakley sunglasses, cheap jordans, ralph lauren outlet, tiffany jewelry, louis vuitton, uggs outlet, replica watches, michael kors outlet, prada handbags, michael kors, prada outlet, uggs on sale, christian louboutin, nike air max, louis vuitton outlet online, louboutin shoes, uggs on sale, nike free, michael kors outlet online, michael kors outlet store, longchamp outlet, cheap oakley sunglasses

ninest123 Ninest said...

north face pas cher, ray ban uk, polo lacoste pas cher, nike air max, nike air max uk, vanessa bruno pas cher, nike roshe uk, nike roshe run pas cher, abercrombie and fitch UK, nike air force, michael kors, michael kors outlet online, polo ralph lauren uk, true religion outlet, lululemon outlet, new balance, timberland pas cher, louboutin pas cher, michael kors uk, nike tn pas cher, hogan sito ufficiale, hermes pas cher, nike blazer pas cher, nike free pas cher, vans pas cher, nike air max pas cher, ralph lauren pas cher, nike air max uk, abercrombie and fitch, lunette oakley pas cher, true religion outlet, true religion jeans, coach outlet, burberry pas cher, sac guess pas cher, converse, north face uk, nike trainers uk, nike free, true religion outlet, hollister uk, mulberry uk, coach outlet store online, coach purses, michael kors, lunette ray ban pas cher, longchamp pas cher, longchamp soldes, jordan pas cher

ninest123 Ninest said...

supra shoes, coach outlet, bottes ugg pas cher, moncler, converse shoes outlet, canada goose pas cher, canada goose uk, juicy couture outlet, juicy couture outlet, moncler pas cher, sac louis vuitton, links of london uk, swarovski jewelry, sac louis vuitton, ugg,uggs,uggs canada, toms shoes, canada goose jackets, karen millen uk, montre pas cher, lancel, canada goose, moncler, uggs outlet, michael kors outlet, moncler uk, ugg uk, barbour, thomas sabo uk, wedding dresses uk, ugg,ugg australia,ugg italia, canada goose outlet, doke & gabbana, barbour jackets uk, replica watches, ugg pas cher, louis vuitton uk, moncler outlet, pandora charms, swarovski uk, marc jacobs, louis vuitton, canada goose outlet, pandora jewelry, louis vuitton, canada goose jackets, moncler, pandora uk, moncler jackets, moncler, hollister, pandora jewelry, canada goose

ninest123 Ninest said...

abercrombie and fitch, nike roshe run, soccer shoes, oakley, wedding dresses, polo ralph lauren, nike air max, nike air max, vans scarpe, valentino shoes, vans outlet, herve leger, p90x workout, beats by dre, iphone 5s cases, soccer jerseys, hollister, ray ban, instyler ionic styler, iphone cases, bottega veneta, insanity workout, s6 cases, timberland boots, giuseppe zanotti, jimmy choo outlet, iphone 6s plus cases, iphone 6 cases, mcm handbags, converse, reebok outlet, babyliss pro, louboutin, lululemon outlet, chi flat iron, mont blanc, new balance shoes, iphone 6 plus cases, north face outlet, salvatore ferragamo, mac cosmetics, asics running shoes, ghd hair, north face outlet, hollister clothing, softball bats, nfl jerseys, hermes handbags, ipad cases, celine handbags, gucci, iphone 6s cases
ninest123 11.24

Post a Comment

Search Web......