dwr无刷新
jsp页面
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<%@ taglib uri="/WEB-INF/taglib.tld" prefix="SysManager" %>
<%@ taglib uri="http://fckeditor.net/tags-fckeditor" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<SysManager:VerifyUser/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>ym_help_center</title>
<link href="../css/main.css" rel="stylesheet" type="text/css"></link>
<link href="/css/style2.css" rel="stylesheet" type="text/css"></link>
<script type="text/javascript" src="/fckeditor/fckeditor.js"></script>
<link rel="StyleSheet" href="../css/dtree.css" type="text/css" />
<script type="text/javascript" src="../js/dtree.js"></script>
<script type='text/javascript' src='../dwr/util.js'></script>
<script type='text/javascript' src='../dwr/engine.js'></script>
<script type='text/javascript' src='../dwr/interface/adviceServlet.js'> </script>
<style type="text/css">
.toporder:link {
color: blue;
}
.toporder:hover {
color: blue;
}
.toporder:visited{
color: blue;
}
.toporder:active {
color: blue;
}
</style>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
body,td,th {
font-size: 12px;
}
-->
</style>
<script>
//返回列表
function backListAdvice(){
var url="/help/listAdvice";
document.forms.editForm.target="mainFrame";
document.forms.editForm.action=url;
document.forms.editForm.submit();
}
//修改
function update(){
var sortName=document.getElementById("sortName");
if(trim(sortName.value).length==0){
alert("分类不能为空!");
sortName.focus();
return false;
}else if(trim(sortName).length>255){
alert("分类长度过长!");
sortName.focus();
return false;
}
//为空则表示未为修改则取原来的
if(trim(selectSortId).length==0)
selectSortId='${help.sortId}';
document.getElementById("selectSortId").value=selectSortId;
var id=document.getElementById("id").value;
var sortId=document.getElementById("selectSortId").value;
adviceServlet.updateAdvice(id,sortId,function(data){
if(data)
alert("修改成功!");
else
alert("修改失败!");
});
}
//增加新的回复或修改当前回复
function reply(){
var savetxt=getEditorHTMLContents('answer');
if(trim(savetxt).length==0){
alert("内容不能为空!");
//savetxt.focus();
return false;
}
if(trim(replyId).length==0){
var mainAdId=document.getElementById("id").value;
adviceServlet.replyAdvice(mainAdId,savetxt,function(data){
if(data){
alert("回复成功!");
//重新加载回复列表
listReply();
//清除
SetEditorContents("answer","");
}
else
alert("回复失败!");
});
}else{
//修改当前回复
adviceServlet.updateReplyAdvice(replyId,savetxt,function(data){
if(data){
alert("修改成功!");
//重新加载回复列表
listReply();
//清除
SetEditorContents("answer","");
replyId="";
}
else
alert("修改失败!");
});
}
}
//取所有回复
var replyCache = { };
function listReply(){
var i=0;
var mainAdId=document.getElementById("id").value;
adviceServlet.listReplyQuestion(mainAdId,function(advices) {
dwr.util.removeAllRows("replybody", { filter:function(tr) {
return (tr.id != "pattern");
}});
var advice, id;
for (var i = 0; i < advices.length; i++) {
advice = advices[i];
id = advice.id;
dwr.util.cloneNode("pattern", { idSuffix:id });
dwr.util.setValue("username" + id, advice.username);
dwr.util.setValue("createtime" + id, advice.createtime);
// dwr.util.setValue("result" + id, help.result);
document.getElementById("replyContent" + id).innerHTML=advice.replyContent;
$("pattern" + id).style.display = "";
replyCache[id]=advice.replyContent;
//交替背景色
if(i%2==0){
$("pattern_1" + id).style.background="#ACB3C1";
$("pattern_2" + id).style.background="#E0E6EF";
$("pattern_3" + id).style.background="#E0E6EF";
}else{
$("pattern_1" + id).style.background="#ACB3C1";
$("pattern_2" + id).style.background="#EFEFEF";
$("pattern_3" + id).style.background="#EFEFEF";
}
}
});
}
//删除空格
function trim(Str,Flag) {
Str = ""+Str;
if(Flag == "l" || Flag == "L") {
RegularExp = /^\s+/gi;
return Str.replace(RegularExp,"");
} else if(Flag == "r" || Flag == "R") {
RegularExp = /\s+$/gi;
return Str.replace(RegularExp,"");
} else {
RegularExp = /^\s+|\s+$/gi;
return Str.replace(RegularExp,"");
}
}
//控制显示
function show(id){
if (document.getElementById(id).style.display=="none"){
document.getElementById(id).style.display="";
}else{
document.getElementById(id).style.display="none";
}
}
//创建树
var d = new dTree('d');
d.add(0,-1,'所有分类');
var names = new Array();
var selectLabelId="";
var selectLabelName="";
var selectSortId="";
var selectSortName="";
//初始分类树
function initTree(){
var sorts='${sorts}';
//alert(sorts);
var sortObjs=sorts.split(";");
for(var i=0;i<sortObjs.length;i++){
var sort=sortObjs[i].split(",");
var id=sort[0];
var parentId=sort[1];
var name=sort[2];
names[id]=name;
d.add(id,parentId,name,'javascript:editClicked('+id+');');
}
//输出节点
document.write(d);
}
//加载要修改的内容
function editClicked(id) {
selectSortId=id;
document.getElementById("sortName").value=names[id];
document.getElementById("selectSortId").value=id;
}
//编辑回复
var replyId="";
function editReply(eleid){
replyId=eleid.substring(4);
var reply = replyCache[eleid.substring(4)];
SetEditorContents("answer",reply);
}
//重置
function clearReply(){
//清除
SetEditorContents("answer","");
replyId="";
}
//预览
function viewHelp(EditorName){
var savetxt=getEditorHTMLContents('answer');
if(trim(savetxt).length==0){
alert("内容不能为空!");
//savetxt.focus();
return false;
}
var result=getEditorHTMLContents(EditorName);
var url="/help/viewHelp?result="+escape(result);
var editForm=document.getElementById("editForm");
editForm.action=url;
editForm.target="_blank";
document.forms.editForm.submit();
}
// 获取编辑器中HTML内容
function getEditorHTMLContents(EditorName) {
var oEditor = FCKeditorAPI.GetInstance(EditorName);
return(oEditor.GetXHTML(true));
}
// 设置编辑器中内容
function SetEditorContents(EditorName, ContentStr) {
var oEditor = FCKeditorAPI.GetInstance(EditorName) ;
oEditor.SetHTML(ContentStr) ;
}
</script>
</head>
<body onLoad="listReply();">
<form name="editForm" id="editForm" action="" method="post" target="mainFrame">
<input type="hidden" id="id" name="id" value="${advice.id}" />
<input type="hidden" id="queryUsername" name="queryUsername" value="${queryUsername}" />
<input type="hidden" id="queryReply" name="queryReply" value="${queryReply}" />
<input type="hidden" id="queryTitle" name="queryTitle" value="${queryTitle}"/>
<input type="hidden" id="querySortId" name="querySortId" value="${querySortId}"/>
<input type="hidden" id="querySortName" name="querySortName" value="${querySortName}"/>
<input type="hidden" id="createtimeBeginDate" name="createtimeBeginDate" value="${createtimeBeginDate}" />
<input type="hidden" id="createtimeEndDate" name="createtimeEndDate" value="${createtimeEndDate}" />
<input type="hidden" id="pageNum" name="pageNum" value="${pageNum}" />
<input type="hidden" id="queryType" name="queryType" value="${queryType}" />
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="white">
<tr><td>
<c:if test="${queryType==1}">
<strong>网站内容 >> 用户反馈 >> 意见建议列表 >> 回复意见建议 </strong>
</c:if>
<c:if test="${queryType==2}">
<strong>网站内容 >> 用户投诉 >> 用户投诉列表 >>回复用户投诉</strong>
</c:if>
<tr><td><hr></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="white">
<tr class="tableheader">
<td>标题</td>
<td>${advice.title}</td>
<td width="6%">提问时间</td>
<td width="11%">${advice.createtime}</td>
</tr>
<tr bgcolor="#CBCFD8">
<td width="8%"> 提问人</td>
<td>${advice.username}
<c:if test="${advice.userid!=-1}">
<a href="/help/detailUser?userId=${advice.userid}" target="_blank">[查看提问人详细信息]</a> </c:if></td>
<td>会员类型</td>
<td>
<c:if test="${advice.userid!=-1}">
VIP
</c:if>
</td>
</tr>
<tr bgcolor="#CBCFD8">
<td>分类</td>
<td colspan="3">
<input type="text" id="sortName" name="sortName" readonly value="${advice.sortName}" >
<input type="button" id="selectSort" name="selectSort" value="选择分类" onClick="show('sortTree');">
<input type="hidden" id="selectSortId" name="selectSortId" value="${advice.sortId}"> </td>
</tr>
<tr bgcolor="#CBCFD8" id="sortTree" style="display:none;">
<td> </td>
<td colspan="3">
<div class="dtree">
<script>
initTree();
</script>
<input type="button" name="openBtn" value="展开所有" onClick="d.openAll();">
<input type="button" name="closeBtn" value="关闭所有" onClick="d.closeAll();">
<input type="button" name="selectBtn" value="隐藏" onClick="show('sortTree');">
</div> </td>
</tr>
<tr bgcolor="#CBCFD8">
<td>提问内容</td>
<td colspan="3">${advice.content}</td>
</tr>
<tr bgcolor="#CBCFD8">
<td> </td>
<td colspan="3"><input name="btnUpdate" type="button" onClick="javascript:update();" value="确认修改"/></td>
</tr>
</table>
</form>
<table border="0" class="rowed grey" width="100%">
<tbody id="replybody">
<tr id="pattern" style="display:none;">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="white" table="table">
<tr id="pattern_1">
<td width="8%">回复人</td>
<td width="74%"><span id="username">username</span></td>
<td width="6%">回复时间</td>
<td width="12%"><span id="createtime">createtime</span></td>
</tr>
<tr id="pattern_2">
<td>回复内容</td>
<td colspan="3">
<span id="replyContent"></span>
</td>
</tr>
<tr id="pattern_3">
<td></td>
<td colspan="3">
<input id="edit" type="button" value="编辑" onClick="editReply(this.id)"/>
</td>
</tr>
</table>
<br>
</td>
</tr>
</tbody>
</table>
<form name="replyForm" id="replyForm" action="/help/answer" method="post" onSubmit="return replay();">
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="white" table>
<tr class="tableheader" >
<td>发表回复</td>
<td> </td>
</tr>
<tr class="tablecontent1" >
<td width="8%">回复内容</td>
<td>
<f:editor id="answer" height="600" width="980" basePath='<%=path + "/FCKeditor/"%>'
imageBrowserURL='<%=path+ "/FCKeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connector"%>'
linkBrowserURL='<%=path+ "/FCKeditor/editor/filemanager/browser/default/browser.html?Connector=connectors/jsp/connector"%>'
flashBrowserURL='<%=path+ "/FCKeditor/editor/filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/jsp/connector"%>'
imageUploadURL='<%=path+ "/FCKeditor/editor/filemanager/upload/simpleuploader?Type=Image"%>'
linkUploadURL='<%=path+ "/FCKeditor/editor/filemanager/upload/simpleuploader?Type=File"%>'
flashUploadURL='<%=path+ "/FCKeditor/editor/filemanager/upload/simpleuploader?Type=Flash"%>'>
</f:editor>
</td>
</tr>
<tr class="tablecontent1" align="left"><td align="2"> </td>
<td align="2">
<input type="button" onClick="javascript:viewHelp('answer');" value="预览"/>
<input name="btnReply" type="button" onClick="reply();" value="确认"/>
<input name="btnReset" type="button" onClick="clearReply();" value="重置"/>
<input name="button" type="button" onClick="javascript:backListAdvice();" value="返回"/>
</td>
</tr>
</table>
</form>
</body>
</html>
dwr配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://www.getahead.ltd.uk/dwr/dwr20.dtd">
<dwr>
<allow>
<create creator="new" javascript="adviceServlet">
<param name="class" value="com.yimei.servlet.help.AdviceServlet" />
</create>
<convert converter="bean" match="com.yimei.beans.help.AdviceBean" />
</allow>
</dwr>