81,095
社区成员
发帖
与我相关
我的任务
分享
function loadDivisions() {
var selectedValue;
var options = document.getElementById("sectorId").options;
for ( var i = 0; i < options.length; i++) {
if (options[i].selected == true)
selectedValue = options[i].value;
}
if (selectedValue=="100") {
document.getElementById("companyId").options.length = 0;
}else{
var params = {
"parentSectorId" : selectedValue
};
var url = "getSubDivision";
document.getElementById("divisionId").options.length = 0;
alert("selectedValue:"+selectedValue);
$.getJSON(url, params, function callback(data) {
alert("here");
alert("Receive:"+data);
option = document.createElement('option');
option.text= "";
option.value = 100;
document.getElementById("divisionId").add(option, 0);
for ( var i = 0; i < data.length; i++) {
option = document.createElement("option");
option.text = data[i].name;
option.value = data[i].id;
alert("optione:"+option.text+"_"+option.value);
var divPosition = document.getElementById("divisionId").options.length;
document.getElementById("divisionId").add(option, divPosition);
}
});
}
}
<?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="default" namespace="/" extends="struts-default">
<action name="toReport" class="action.ReportAction"
method="toReport">
<result name="success">/report.jsp</result>
</action>
<action name="getSubDivision" class="action.ReportAction"
method="getSubDivision">
<interceptor-ref name="defaultStack" />
</action>
</package>
</struts>
package action;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.interceptor.ServletResponseAware;
import com.opensymphony.xwork2.ActionSupport;
import dao.DB;
import model.Organization;
public class ReportAction extends ActionSupport implements ServletResponseAware{
private List<Organization> sectors;
private List<Organization> divisions;
private String parentSectorId;
private HttpServletResponse response;
public String toReport() {
sectors = DB.getAllSectors();
System.out.println("secots:"+sectors);
return SUCCESS;
}
public String getSubDivision() {
if (parentSectorId == "") {
return null;
}
int secId = Integer.parseInt(parentSectorId);
divisions = DB.getDivisionsBySecId(secId);
System.out.println("SectorId "+ secId +"'s divisions:");
String str = "";
for(Organization div: divisions) {
str += div.getId()+":"+div.getName();
}
try {
this.getResponse().getWriter().print("Action say");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return ERROR;
}
return null;
}
public List<Organization> getSectors() {
return sectors;
}
public void setSectors(List<Organization> sectors) {
this.sectors = sectors;
}
public List<Organization> getDivisions() {
return divisions;
}
public void setDivisions(List<Organization> divisions) {
this.divisions = divisions;
}
public String getParentSectorId() {
return parentSectorId;
}
public void setParentSectorId(String parentSectorId) {
this.parentSectorId = parentSectorId;
}
public HttpServletResponse getResponse() {
return response;
}
@Override
public void setServletResponse(HttpServletResponse response) {
// TODO Auto-generated method stub
this.response = response;
}
}