这是以下2个链接的延续....由于我无法发布任何评论......
1。 Populating a table based on values chosen from a drop down in struts2 application
和
我也有相同的场景,我需要根据下拉列表中的选定值打印表格,在我的谷歌搜索中我得到了这个页面,我在这里使用了建议。但是当我在下拉列表中选择一个值时,我会在桌面上打印并且页面仍然保持在同一页面而没有任何更新,下面是我的代码...帮我解决这个问题...
的javascript
<script type="text/javascript">
function showAllocationStatusJavaScript(){
var batchURL1="<s:property value="#batchURL"/>";
$.ajax({
url:batchURL1,
type: 'get',
beforeSend: function(){
$("#loading").show();
alert("parsed");
},
success: function(result){
if(result!=''){
$('myTableWrapper').html(result);
} else {
alert(result);
}
},
});
}
</script>
在jsp正文中
<s:select label="Select Batch" headerKey="-1" headerValue="Select a Batch..."list="%{#session.Batchs}" Value="batch" name="batch" onchange="showAllocationStatusJavaScript()" id="batch"/>
网址标记
<s:url action="doShowAllocationStatus" var="batchURL"><param value="%{batch}"/></s:url>
此表打印我的列表
<div id="myTableWrapper">
<table align="center" border="2">
<tr>
<th>TAN</th>
<th>Curator</th>
<th>Curator Status</th>
<th>QC</th>
<th>QC Status</th>
</tr>
<s:iterator value="allocationList" >
<tr>
<td><s:property value="tan"/></td>
<td><s:property value="curator"/></td>
<td><s:property value="curator_status"/></td>
<td><s:property value="qc"/></td>
<td><s:property value="qc_status"/></td>
</tr>
</s:iterator>
</table>
</div>
struts.xml中
<action name="doShowAllocationStatus" class="controller.AllocateTAN" method="showAllocationStatus" >
<result name="success" type="dispatcher" >Allocation.jsp</result>
AllocateTAN操作类
//Fields that hold data...
private List<BatchInfo> allocationList =new ArrayList<BatchInfo>();
private String batch;
private List<String> batchs = new ArrayList<String>();
private String TAN;
private List<String> Tans = new ArrayList<String>();
private String user;
private List<String> users = new ArrayList<String>();
//and all getters and setters....
.....
//variable used to access DataBase...
CationDAO dao1 = new CationDAO() ;
//flow 1.: making all details available for the allocate TAN page...when page page is loaded 1st time
public String AllocatingTANpageDetails() throws SQLException{
Map<String, Object>session=ActionContext.getContext().getSession();
this.batchs=dao1.Batch_List();
session.put("Batchs", batchs);
//Tans=dao1.Tan_list(getBatch());
this.users=dao1.Users_List();
session.put("users", users);
return SUCCESS;
}
private void showTANlist(String Batch1) throws SQLException{
Map<String, Object>session=ActionContext.getContext().getSession();
Tans=dao1.Tan_list(Batch1);
session.put("Tans", Tans);
}
//flow 2.: showing Allocation Status in Table form...in same page
public String showAllocationStatus() throws SQLException {
Map<String, Object>session=ActionContext.getContext().getSession();
//setBatch(batch_value);
session.put("Batch",batch);
showTANlist(batch);
System.out.println("Processing Allocation List... ");
this.allocationList=(List<BatchInfo>)dao1.status(batch);
System.out.println("Finished...");
return SUCCESS;
}
//execute method form allocating a TAN for a user...
public String execute(){
return SUCCESS;
}
答案 0 :(得分:1)
您的jQuery选择器不正确:
$('myTableWrapper').html(result);
DOM元素ID由前导#
字符指定;这应该是:
$('#myTableWrapper').html(result);
你的$.ajax
参数中也有一个无关的尾随逗号,这些逗号在某些浏览器上会中断,应该总是被删除。
function showAllocationStatusJavaScript() {
$.ajax({
url: "<s:property value='#batchURL'/>",
type: 'get',
beforeSend: function() {
$("#loading").show();
},
success: function(result) {
if (result != '') {
$('#myTableWrapper').html(result);
}
$("#loading").hide();
}
});
}
答案 1 :(得分:0)
最后我发现答案...... 我在jquery-ajax代码和struts.xml中做了一些更正......在这里它们是......
jquery-ajax代码
<head>
<script type="javascript" src="jquery-1.7.js"></script>
<head>
<script type="text/javascript">
$(document).ready(function()
{
$('#batchID').change(function(event) {
var batch=$('#batchID').val();
alert("inside change fn."+batch);
$.ajax({
url : "doShowAllocationStatus.action",
data : "batch="+batch,
success : function(html) {
alert("success");
$("#table").html(html);
},
error : function(html) {
alert("error");
}
});
});
});
</script>
现在我在这里编写了我在上面的问题中显示的表格代码,在一个新的jsp页面(AllocationStatusTable.jsp)中并包含它...
<div id=table>
<s:include value="AllocationStatusTable.jsp" />
</div>
稍后在struts.xml中我重新编写了动作配置,
<action name="doShowAllocationStatus" class="controller.AllocateTAN" method="showAllocationStatus" >
<result name="input" >Allocation.jsp</result>
<result name="error" >Allocation.jsp</result>
<result>AllocationStatusTable.jsp</result>
</action>
所以操作的结果指向新的jsp页面(AllocationStatusTable.jsp)。
最后,当我在我的选项列表中选择一个批次时,我将根据我选择的批次获取我的表...:)