====== [적용 예] Ajax Support ======
===== 개요 =====
Ajax Support Service 를 적용해서 민원목록 검색시, 검색어 자동완성기능을 제공한다.
==== Configuration ====
=== WEB_INF\web.xml ===
sourceloader
net.sourceforge.ajaxtags.servlets.SourceLoader
prefix
/ajaxtags
sourceloader
/ajaxtags/js/*
sourceloader
/ajaxtags/img/*
sourceloader
/ajaxtags/css/*
==== Source ====
=== egovframework\rte\cvpl\web\view\CvplAjaxXmlView.java ===
package egovframework.rte.cvpl.web.view;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.view.AbstractView;
public class CvplAjaxXmlView extends AbstractView {
@Override
protected void renderMergedOutputModel(Map model,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
response.setContentType("text/xml;");
response.setHeader("Cache-Control", "no-cache");
response.setCharacterEncoding("UTF-8");
PrintWriter writer = response.getWriter();
writer.write((String) model.get("ajaxXml"));
}
}
=== egovframework\rte\cvpl\web\view\CvplXmlView.java ===
package egovframework.rte.cvpl.web.view;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.view.AbstractView;
import sun.text.CompactShortArray.Iterator;
public class CvplXmlView extends AbstractView {
@Override
protected void renderMergedOutputModel(Map model,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
for(Iterator it = (Iterator) model.keySet().iterator(); it.hasNext();){
}
}
}
=== egovframework\rte\cvpl\web\EgovCvplCnsltController.java ===
...
/** 공백이 아닌 경우, 검색어의 중복을 체크한다. */
String searchKeyword = searchVO.getSearchKeyword();
if (!searchKeyword.equals("")) {
String dupSrchKeyword = cvplCnsltService.checkDupSearchKeywordList(searchKeyword);
if (!searchKeyword.equals(dupSrchKeyword)) {
/** 검색어를 등록한다. */
cvplCnsltService.insertSearchKeywordList(searchKeyword);
}
}
...
@RequestMapping("/cvpl/egovCvplCnsltSearchAjax.do")
protected ModelAndView handle(@RequestParam("searchKeyword") String searchKeyword)
throws Exception {
ModelAndView model = new ModelAndView(new CvplAjaxXmlView());
List searchKeywordList = cvplCnsltService.selectSearchKeywordList(searchKeyword);
AjaxXmlBuilder ajaxXmlBuilder = new AjaxXmlBuilder();
for(String srchkeyword:searchKeywordList){
ajaxXmlBuilder.addItem(srchkeyword, srchkeyword, false);
}
model.addObject("ajaxXml",ajaxXmlBuilder.toString());
return model;
}
=== WEB-INF\jsp\egovframework\rte\cvpl\EgovCvplCnsltList.jsp ===
<%@ taglib prefix="ajax" uri="http://ajaxtags.sourceforge.net/tags/ajaxtags" %>
...
...
...