Strut-Ajax - display states when Country selected
4 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Nina_Anderson
Posted On:   Monday, August 13, 2007 05:32 AM

Hi, I have a struts JSP page that has a Country drop-down list and a State drop-down list. I want to be able to retrieve a list of States when a Country is selected. I've never used Ajax before. My jsp page is able to send the request to my Struts Action process. However, the data that gets forwarded back to the JSP page is NOT making it into the responseText. I'm writing the data into the PrintWriter object but that data is not making it back. Can someone Please let me know what I'm doing wrong. Here's my code: /// JSP //// if (req.status == 200) { // OK response alert(req.respon   More>>

Hi,


I have a struts JSP page that has a Country drop-down list and a State drop-down list. I want to be able to retrieve a list of States when a Country is selected. I've never used Ajax before.


My jsp page is able to send the request to my Struts Action process. However, the data that gets forwarded back to the JSP page is NOT making it into the responseText. I'm writing the data into the PrintWriter object but that data is not making it back.


Can someone Please let me know what I'm doing wrong.


Here's my code:


/// JSP ////



if (req.status == 200) { // OK response


alert(req.responseText);

textToSplit = document.createTextNode(req.responseText);



if(textToSplit == '803'){
alert("No select option available on the server")
}


//Split the document
returnElements=textToSplit.split("||")


//Process each of the elements
for ( var i=0; i


valueLabelPair = returnElements[i].split(";")
alert("label - " + valueLabelPair[0]);
document.forms['SearchResultForm'].selectedState.options.length = returnElements.length;
document.forms['SearchResultForm'].selectedState.options[i] = new Option(valueLabelPair[0], valueLabelPair[1]);
}
}
}

}



]]>











			






Country







State:







///// STRUTS Action ////


public class MainSearchDisplayAction extends Action {
/*
* Generated Methods
*/


ServletContext context = null;

public void setServlet(ActionServlet servlet)
{
context = servlet.getServletContext();
}


/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping_, ActionForm form_,
HttpServletRequest request_, HttpServletResponse response_) {


DynaValidatorForm form = (DynaValidatorForm) form_;


if( request_.getParameter("selectedCountry") != null && request_.getParameter("selectedCountry").length() > 0)
{
PopulateAjaxLabelValue populateAjaxValues = new PopulateAjaxLabelValue();
SearchBS searchBS = new SearchBS();
String selectedCountry = null;


try {

response_.setContentType("text/xml");
PrintWriter out = response_.getWriter();


List states = searchBS.getStatesByCountry( new Integer(selectedCountry) );
//Make a String representation in format label;value||label;value
String outLine = populateAjaxValues.makeOutputString(states);
System.out.println("Response String - " + outLine);
out.print(outLine);

} catch (Exception e) {

System.out.println("Exception occurred - " + e);
}

}

return mapping_.findForward("mainSearch");
}


///// STRUTS CONFIG /////







Thanks in Advance

   <<Less

Re: Strut-Ajax - display states when Country selected

Posted By:   Anonymous  
Posted On:   Tuesday, August 28, 2007 06:20 AM

Hi Nina .
Even I am searching for the same code . I tried with javascript but was not successful .If u get code please forward it to me.
please send me the code .
Thanks In Advance.

Re: Strut-Ajax - display states when Country selected

Posted By:   Anonymous  
Posted On:   Friday, August 24, 2007 10:51 PM

Hi Nina

Though I myself is not an expert at the concern area, I always take help from some professional service providers, currently I am taking the services from http://www.techhelpformarketers.com for my current project. "They are an assembled team of Tech Professional with Extensive Experience in taking down IT task or IT technical problems giving you the Shortest Turnaround Time possible."

Hope it's helpful to you!

[wilkin]

Re: Strut-Ajax - display states when Country selected

Posted By:   Anonymous  
Posted On:   Thursday, August 16, 2007 08:08 PM

Hi Nina

Though I myself is not an expert at the concern area, I always take help from some professional service providers, currently I am taking the services from http://www.techhelpformarketers.com for my current project. "They are an assembled team of Tech Professional with Extensive Experience in taking down IT task or IT technical problems giving you the Shortest Turnaround Time possible."

Hope it's helpful to you!

[wilkin]

Re: Strut-Ajax - display states when Country selected

Posted By:   Anonymous  
Posted On:   Tuesday, August 14, 2007 01:57 PM

Hi strut

If still you are facing problem then I will recommend you http://www.techhelpformarketers.com

Here is an extract of the sales letter to give you a better idea of what they offer,

"They are an assembled team of Tech Professional with Extensive Experience in taking down IT task or IT technical problems giving you the Shortest Turnaround Time possible."


Hope it's helpful to you!

[mac_jsn]
About | Sitemap | Contact