Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Ajax struts
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.
 
Looking forward to hear from you..
 
regards,
sunitha
Posted 28-Dec-11 2:47am
Comments
Sunasara Imdadhusen at 28-Dec-11 8:43am
   
Please provide snippet of code!!
sunithamm1 at 29-Dec-11 1:33am
   
Hi
This is the code snippet:
 
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>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
function show_details() {
dojo.event.topic.publish("populate");
}
</script>
</head>
<body>

<table>
<tr>
<td>TRANSPORTER:</td>
<td><s:select list="{'APPOLO','RAJENDRA','SUMAN'}" headerkey="0" headervalue="-Please Select-" önchange="show_details()" id="sel_transporter" name="sel_transporter">
</s:select></td>
</tr>
<tr>
<td>TRUCK:</td>
<s:url action="populateTruckAction" id="truck_url"></s:url>
<td><s:div href="%%7Btruck_url%7D" listentopics="populate" formid="innerForm" theme="ajax" id="truckDiv"></s:div>
</td>
</tr>
<tr>
<td>Submit:</td>
<td>PRINT
</td>
</tr>
</table>

</body>
</html>
 
MyActionClass
 
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 transList = new LinkedList();
private LinkedList truckList = new LinkedList();
 
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(sel_transporter+"---"+sel_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 getTransList() {
return transList;
}
 
public void setTransList(LinkedList transList) {
this.transList = transList;
}
 
public LinkedList getTruckList() {
return truckList;
}
 
public void setTruckList(LinkedList truckList) {
this.truckList = truckList;
}
}
 
trucklist.jsp
-------------
 

<%@ taglib prefix="s" uri="/struts-tags"%>
<s:select list="truckList" headerkey="0" name="sel_truck" id="sel_truck" xmlns:s="#unknown"></s:select>
 
struts.xml
-----------
 
<!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>
<constant name="struts.devMode" value="false"></constant>
<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">/resu

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi all,
I got it solved.
 
i wrote a javascript function in index.jsp
 
function test()
{
       document.innerForm.action = "printAction.action";
       document.innerForm.submit();
}
 
Then on cliking print link,called that function.
<a id="print_anchor" onclick="test()">PRINT </a>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 520
1 Mathew Soji 335
2 BillWoodruff 260
3 OriginalGriff 215
4 Afzaal Ahmad Zeeshan 188
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,028
3 Manas Bhardwaj 4,539
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 2 Jan 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100