tags:

views:

35

answers:

1

Hi, I am trying to create a form that lets users add 3 schools. They first select select a state then college list will be populated based on the state. States are loaded in prepare method. I'm using struts 2.1.8 and struts-jquery 2.3.1.

<label for="state1">State: </label>
            <s:select 
                id="state1" 
                name="state1" 
                list="stateMap"
                headerKey="-1" 
                headerValue="Please Select a State"
                onchange="getColleges();"
            /><br />


            <label for="college1">College 1: </label>
            <sj:select 
                href="loadCollegesByState"
                id="college1" 
                name="college1" 
                list="collegeList"
                listKey="key"
                listValue="value"
                listenTopics="state1_change"
                reloadTopics="state1_change"
                headerKey="-1" 
                headerValue="Please Select a College"
            /><br />

javascript

<script type="text/javascript">
function getColleges() {
    alert('loading....schools');
    $.publish('state1_change');

}
</script>

This works as 2nd is a drop down menu. But I want to make it autocompleter. How can I achieve that? The following doesn't work.

<sj:autocompleter
        href="loadCollegesByState"
        id="college1" 
        name="college1" 
        list="collegeList"
        listKey="key"
        listValue="value"
        listenTopics="state1_change"
        reloadTopics="state1_change"
/><br />
A: 

how do you have defined your href url? I don't see any s:url tag in your code?

<s:url id="collegesurl" action="loadCollegesByState" namespace="/"/>
            <sj:select 
                href="%{collegesurl}"
                id="college1" 
                name="college1" 
                list="collegeList"
                listKey="key"
                listValue="value"
                listenTopics="state1_change"
                reloadTopics="state1_change"
                headerKey="-1" 
                headerValue="Please Select a College"
            />

also you can take a look at your XHR Network traffic with firebug to see if your json action was called successfully.

jogep
href="action_name" also works. It seems, I'd just forgotten to restart server after making change to my java file. This dependent drop down works. What changes would I need to make to have an autocompleter?
Nishant
I changed it to autocompleter but that doesn't work, action is not being called. See code above.
Nishant