EasyUI Tree tree is loaded synchronously and stored in application
7014 단어 application
Use the EasyUI tree control to load the unit tree, the requirements need to be loaded synchronously, and start to use ajax to request data, so you need to request data every time, which seriously affects the performance. Now it is changed to obtain data when the web starts, store it in the application, and the foreground page obtains the data loading unit tree.
Code before:
$('#orgTree').tree({
url:'orginfo/searchOrgTree?searchKey='+encodeURIComponent(searchKey),
onClick : zTreeOnClick,
onDblClick : closeOrgWin,
onLoadSuccess:function(){
//
var rootNode=$('#orgTree').tree('getRoot');
$('#orgTree').tree('expand', rootNode.target);
}
});
Code now:
Add to web.xml:
<servlet>
<servlet-name>InitOrgTreeData</servlet-name>
<servlet-class>ustcsoft.common.st.InitOrgTreeData</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
Corresponding Servlet:
package ustcsoft.common.st;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.json.JSONException;
import org.apache.struts2.json.JSONUtil;
import ejb.common.st.Ejb3Factory;
import ejb.orginfo.st.QtyCOrganizationFacadeLocal;
import ejb.util.st.ComBoxTreeNode;
public class InitOrgTreeData extends HttpServlet {
//EJB
public static Ejb3Factory factory;
protected static Log logger = LogFactory.getLog(HttpServlet.class);
static {
factory = Ejb3Factory.getInstance();
}
/**
* Constructor of the object.
*/
public InitOrgTreeData() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
logger.info("Get ORG TREE DATA HERE!");
String searchKey="";
List<ComBoxTreeNode> list = new ArrayList<ComBoxTreeNode>();
QtyCOrganizationFacadeLocal OrgLocal = (QtyCOrganizationFacadeLocal) factory
.getEJB("QtyCOrganizationFacade");
List orgList = OrgLocal.findSearchOrgTree(searchKey);
list=CommDataUtil.buildNodeTree(orgList);
try {
String result = JSONUtil.serialize(list);
// application
this.getServletContext().setAttribute("OrgData",result);
} catch (JSONException e) {
logger.error("InitOrgTreeData ");
}
}
}
Processing of the front page:
<%
String orgData=(String)application.getAttribute("OrgData");
%>
<script language="javascript">
// , :var orgData='<%=orgData%>'
var orgData=<%=orgData%>;
$('#orgTree').tree({
// ,url--->data
// url:'orginfo/searchOrgTree
?searchKey='+encodeURIComponent(searchKey),
data:orgData,
onClick : zTreeOnClick,
onDblClick : closeOrgWin,
onLoadSuccess:function(){
//
var rootNode=$('#orgTree').tree('getRoot');
$('#orgTree').tree('expand', rootNode.target);
}
});
</script>
Due to the busy work, I made a little record, which is relatively rough, so it is convenient for my own reference.
At the same time, any corrections are welcome.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Pre-Query SamplesValidate the current query criteria or provide additional query criteria programmatically, just before sending the SELEC...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.