You can use Ajax.
I have implemented it for Struts 2.

See my code below:


<script language="javascript" type="text/javascript">

function getXMLHTTP() {
                var xmlhttp=false;      
                try{
                        xmlhttp=new XMLHttpRequest();
                }
                catch(e)        {               
                        try{                    
                                xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch(e){
                                try{
                                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                                }
                                catch(e1){
                                        xmlhttp=false;
                                }
                        }
                }                       
                return xmlhttp;
    }
        
        function loadRegions(childRegion, parentRegion)
         {              
                var regionId=parentRegion.value;
                var strURL="user/noDeco_loadRegions.action?regionId="+regionId;
                var req = getXMLHTTP();
                
                if (req) {                      
                        req.onreadystatechange = function() {
                                if (req.readyState == 4) {
                                        // only if "OK"
                                        if (req.status == 200) {                
                                
                                                var resultList 
=req.responseText;
                                                //alert(resultList);            
                                
                                                resultList = 
resultList.split(',');     
                                                var intCounter = 0;     
                                                var option = new 
Option('Select','');   
                                                
document.userForm.elements[childRegion].options[intCounter] = option;   
                                                intCounter++;           
                                                for(i=0; i<resultList.length; 
i=i+2)
                                                        {                       
                                
                                                                var option = 
new Option(resultList[i+1],resultList[i]);
                                                                 
document.userForm.elements[childRegion].options[intCounter] =
option;
                                                                 intCounter++;
                                                        }
                                                        
                                                //alert("ThereXMLHTTP:\n" + 
req.responseText);                                  
                                        } else {
                                                alert("There was a problem 
while using XMLHTTP:\n" + req.statusText);
                                        }
                                }                               
                        }                       
                        req.open("GET", strURL, true);
                        req.send(null);
                }               
        }
        
        function loadProvinces(parentRegion) 
        {       
                document.userForm.provinceId.options.length = 0;
                var option = new Option('Select','');   
                document.userForm.provinceId.options[0] = option;
                //alert("value is " +parentRegion.value);
                if (parentRegion.value != '') 
                {       
                        //alert("value not null " +parentRegion.value);         
                        loadRegions('provinceId',parentRegion);
                }                       
        }

        
</script>

<s:select  name="countryId" key="user.label.country"  required="true"
                                           headerKey=""  headerValue="Select"   
onchange="loadProvinces(this)"
                                           list="countryList" 
listKey="regionId" listValue="description"        >
                                <s:param name="labelcolspan" value="%{1}" />
                                <s:param name="inputcolspan" value="%{1}" />    
                        </s:select>                                             
                   
                        <s:select name="provinceId" key="user.label.province"  
required="true"  
                                          headerKey=""  headerValue="Select"    
                                  list="provinceList"
listKey="regionId" listValue="description"      >
                                <s:param name="labelcolspan" value="%{1}" />
                                <s:param name="inputcolspan" value="%{1}" />    
                        </s:select>     

You have to map the action in struts.xml file.

And code in my action class is:

@SkipValidation
        public void loadRegions()
        {
                try
                {
                        String regions ="";             
                        regionList = 
commonService.loadRegionListByParentRegion(regionId);
                        
                        StringBuffer regionStr = new StringBuffer();
                        if(regionList != null && regionList.size()>0)
                        {
                                Iterator iter = regionList.iterator();
                                while(iter.hasNext())
                                {
                                        Map optionMap = (Map)iter.next();
                                
regionStr.append((String)optionMap.get(TxnServerI.REGION_ID)).append(",")
                                                
.append((String)optionMap.get(TxnServerI.REGION_DESCRIPTION)).append(",");
                                }               
                                regions = regionStr.toString().substring(0, 
(regionStr.length()-1));
                        }                        
                
                        _response.setContentType("text/xml");
                        PrintWriter writer = _response.getWriter();
                        writer.write(regions);
                }
                catch (Exception e) 
                {
                        e.printStackTrace();                    
                }                                       
        }



Rajiv






Nisha Akash wrote:
> 
> Hello everyone,
> 
> There is a problem in my  struts 1.x code is that 
> 
> Suppose I have 2 combobox say country,city & initially country contains 
> some countyname   from database  .Now i want that when we select any item
> or any country from country combobox then other city combobox contains
> data from database according to each country
> 

-- 
View this message in context: 
http://www.nabble.com/struts-tp20162279p20181408.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to