Hi all, I am having two select boxes in my jsp page. I need to populate second select box depending upon the value selected in first select box. I am able to do this. But the problem is i am not getting the value selected in the second select box in the action class. i have provided getters and setters for both select boxes.
The code snippets are given below index.jsp ---------- <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <s:head theme="ajax" /> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <s:form id="innerForm" name="innerForm"> <table> <tr> <td>TRANSPORTER:</td> <td><s:select list="{'APPOLO','RAJENDRA','SUMAN'}" headerKey="0" headerValue="-Please Select-" onchange="show_details()" id="sel_transporter" name="sel_transporter"> </s:select></td> </tr> <tr> <td>TRUCK:</td> <s:url action="populateTruckAction" id="truck_url" /> <td><s:div href="%{truck_url}" listenTopics="populate" formId="innerForm" theme="ajax" id="truckDiv"></s:div> </td> </tr> <tr> <td>Submit:</td> <td><a id="print_anchor" href="<s:url action='printAction'/>">PRINT </td> </tr> </table> </s:form> </body> </html> trucklist.jsp ------------ <%@ taglib prefix="s" uri="/struts-tags"%> <s:select list="truckList" headerKey="1" name="sel_truck" id="sel_truck"></s:select> result.jsp ----------- <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <s:form name="form1"> Transporter:<s:property value="sel_transporter"/> Truck:<s:property value="sel_truck"/> </s:form> </body> </html> struts.xml ----------- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="false" /> <package name="" extends="struts-default"> <action name="populateTruckAction" class="com.sample.MainAction" method="populateTruck"> <result name="input">/index.jsp</result> <result name="success">/trucklist.jsp</result> </action> <action name="printAction" class="com.sample.MainAction" method="print"> <result name="success">/result.jsp</result> </action> </package> </struts> MainAction.java ----------------- package com.sample; import java.util.LinkedList; import com.opensymphony.xwork2.ActionSupport; public class MainAction extends ActionSupport { private static String sel_transporter; private static String sel_truck; private LinkedList<String> transList = new LinkedList<String>(); private LinkedList<String> truckList = new LinkedList<String>(); public String populateTruck() { System.out.println("inside populate Truck...." + sel_transporter); if (sel_transporter.equals("APPOLO")) { truckList.add("APP01"); truckList.add("APP02"); } else if (sel_transporter.equals("RAJENDRA")) { truckList.add("RAJ01"); truckList.add("RAJ02"); } else { truckList.add("SUM01"); truckList.add("SUM02"); } return SUCCESS; } public String print() { System.out.println(getSel_transporter()+"---"+getSel_truck()); return SUCCESS; } public String getSel_transporter() { return sel_transporter; } public void setSel_transporter(String sel_transporter) { MainAction.sel_transporter = sel_transporter; } public String getSel_truck() { return sel_truck; } public void setSel_truck(String sel_truck) { MainAction.sel_truck = sel_truck; } public LinkedList<String> getTransList() { return transList; } public void setTransList(LinkedList<String> transList) { this.transList = transList; } public LinkedList<String> getTruckList() { return truckList; } public void setTruckList(LinkedList<String> truckList) { this.truckList = truckList; } } Looking forward to hear from you.... Regards, Sunitha -- View this message in context: http://struts.1045723.n5.nabble.com/using-ajax-to-populate-select-box-tp5109350p5109350.html Sent from the Struts - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org