You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Nisha Akash <ni...@gmail.com> on 2008/10/25 10:33:04 UTC

struts

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-tp20162279p20162279.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts

Posted by Nisha Akash <ni...@gmail.com>.
Thanks for ur reply
-- 
View this message in context: http://www.nabble.com/struts-tp20162279p20317788.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts

Posted by Rajiv Singla <ra...@gmail.com>.
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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: struts

Posted by Martin Gainty <mg...@hotmail.com>.
any new development you might want to think about starting with Struts2..its AOP based with interceptors
and support ajax controls on the UI with Dojo theme=ajax controls
Below is an example which enables you to use localised text strings to display to the user
http://struts.apache.org/2.0.11.2/docs/localization.html

Martin
______________________________________________ 
Disclaimer and confidentiality note 
Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. 


> Date: Sun, 26 Oct 2008 21:31:06 +0100
> From: reno.rkcrew@free.fr
> To: user@struts.apache.org
> Subject: Re: struts
> 
> Nisha,
> 
> there is no problem in your struts code. Your problem is that Struts 
> cannot do this for you except if you send parameters to the action (that 
> is a bit heavy)
> 
> you can do this using javascript (ajax call to get the datas associated 
> to a country)
> check out this post
> http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=58&t=007607
> and this article
> http://www.omnytex.com/articles/xhrstruts/
> and
> http://www.scribd.com/doc/123490/Ajax-Tutorial
> and
> ....
> 
> google is your friend
> 
> > 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
> >   
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

_________________________________________________________________
Want to read Hotmail messages in Outlook? The Wordsmiths show you how.
http://windowslive.com/connect/post/wedowindowslive.spaces.live.com-Blog-cns!20EE04FBC541789!167.entry?ocid=TXT_TAGLM_WL_hotmail_092008

Re: struts

Posted by supareno <re...@free.fr>.
Nisha,

there is no problem in your struts code. Your problem is that Struts 
cannot do this for you except if you send parameters to the action (that 
is a bit heavy)

you can do this using javascript (ajax call to get the datas associated 
to a country)
check out this post
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=58&t=007607
and this article
http://www.omnytex.com/articles/xhrstruts/
and
http://www.scribd.com/doc/123490/Ajax-Tutorial
and
....

google is your friend

> 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
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org