DWZ (JUI) 教程 DWZ LookUp Suggest 教程

DWZ (JUI) 教程 DWZ LookUp Suggest 教程

最近有人问 Lookup 和 Suggest 的问题 ,我做了一个小的 Demo 希望给大家有所帮助,我也简单分析一下流程,有时间的话我也简单录个视频,讲一下原理


效果图片


DWZ (JUI) 教程 DWZ LookUp Suggest 教程_第1张图片

单个查找带回

DWZ (JUI) 教程 DWZ LookUp Suggest 教程_第2张图片


DWZ (JUI) 教程 DWZ LookUp Suggest 教程_第3张图片

jsp 代码lookup.jsp

  1. <%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%>
  2. <h2class="contentTitle">suggest+lookup</h2>
  3. <formaction="demo/common/ajaxDone.html?navTabId=masterList&callbackType=closeCurrent"method="post"class="pageFormrequired-validate"onsubmit="returnvalidateCallback(this,navTabAjaxDone)">
  4. <divclass="pageContent">
  5. <divclass="pageFormContent"layoutH="97">
  6. <dlclass="nowrap">
  7. <dt>用户名称:</dt>
  8. <dd>
  9. <inputname="test1.id"value=""type="text"/>
  10. <inputclass="required"name="test1.name"type="text"postField="name"suggestFields="name"
  11. suggestUrl="./lookup!suggest.do"lookupGroup="test1"/>
  12. <spanclass="info">(suggest)</span>
  13. </dd>
  14. </dl>
  15. <dlclass="nowrap">
  16. <dt>(单个)用户名称:</dt>
  17. <dd>
  18. <inputname="test2.id"value=""type="text"/>
  19. <inputclass="required"name="test2.name"type="text"/>
  20. <aclass="btnLook"href="./lookup!searchUser.do"warn="用户"lookupGroup="test2">查找带回</a>
  21. <spanclass="info">(lookup)</span>
  22. </dd>
  23. </dl>
  24. <divclass="divider"></div>
  25. <dlclass="nowrap">
  26. <dt>(多个)用户名称:</dt>
  27. <dd>
  28. <inputname="test3.id"value=""type="text"/>
  29. <inputclass="required"name="test3.name"type="text"/>
  30. <aclass="btnLook"href="./lookup!searchUsers.do"warn="用户"lookupGroup="test3">查找带回</a>
  31. <spanclass="info">(lookup)</span>
  32. </dd>
  33. </dl>
  34. <divclass="divider"></div>
  35. </div>
  36. <divclass="formBar">
  37. <ul>
  38. <li><divclass="buttonActive"><divclass="buttonContent"><buttontype="submit">保存</button></div></div></li>
  39. <li><divclass="button"><divclass="buttonContent"><buttonclass="close"type="button">关闭</button></div></div></li>
  40. </ul>
  41. </div>
  42. </div>
  43. </form>

searchUser.jsp
  1. <%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%>
  2. <%@taglibprefix="c"uri="http://java.sun.com/jsp/jstl/core"%>
  3. <formid="pagerForm"method="post"action="user!searchUser.do">
  4. <inputtype="hidden"name="status"value="${param.status}">
  5. <inputtype="hidden"name="keywords"value="${param.keywords}"/>
  6. <inputtype="hidden"name="pageNum"value="1"/>
  7. <inputtype="hidden"name="pages.pageNo"value="${pages.pageNo}"/>
  8. <inputtype="hidden"name="pages.pageSize"value="${pages.pageSize}"/>
  9. </form>
  10. <divclass="pageHeader">
  11. <formrel="pagerForm"method="post"action="demo/database/dwzOrgLookup.html"onsubmit="returndwzSearch(this,'dialog');">
  12. <divclass="searchBar">
  13. <ulclass="searchContent">
  14. <li>
  15. <label>用户名称:</label>
  16. <inputclass="textInput"name="user.name"value="${user.name}"type="text">
  17. </li>
  18. </ul>
  19. <divclass="subBar">
  20. <ul>
  21. <li><divclass="buttonActive"><divclass="buttonContent"><buttontype="submit">查询</button></div></div></li>
  22. </ul>
  23. </div>
  24. </div>
  25. </form>
  26. </div>
  27. <divclass="pageContent">
  28. <tableclass="table"layoutH="118"targetType="dialog"width="100%">
  29. <thead>
  30. <tr>
  31. <thorderfield="orgName">序号</th>
  32. <thorderfield="orgNum">用户名称</th>
  33. <thorderfield="leader">用户电话</th>
  34. <thorderfield="creator">请选择</th>
  35. </tr>
  36. </thead>
  37. <tbody>
  38. <c:forEachvar="user"items="${pages.pages}"varStatus="status">
  39. <trtarget="sid_user"rel="${user.id}">
  40. <td>${status.count+(pages.pageNo-1)*pages.pageSize}</td>
  41. <td>${user.realName}</td>
  42. <td>${user.phone}</td>
  43. <td>
  44. <aclass="btnSelect"href="javascript:$.bringBack({id:'${user.id}',name:'${user.realName}'})"title="查找带回">选择</a>
  45. </td>
  46. </tr>
  47. </c:forEach>
  48. </tbody>
  49. </table>
  50. <divclass="panelBar">
  51. <divclass="pages">
  52. <span>显示</span>
  53. <selectclass="combox"name="numPerPage"onchange="navTabPageBreak({numPerPage:this.value})">
  54. <optionvalue="20">20</option>
  55. <optionvalue="50">50</option>
  56. <optionvalue="100">100</option>
  57. <optionvalue="200">200</option>
  58. </select>
  59. <span>条,共${pages.count}条</span>
  60. </div>
  61. <divclass="pagination"targetType="navTab"totalCount="${pages.count}"numPerPage="${pages.pageSize}"pageNumShown="10"currentPage="${pages.pageNo}"></div>
  62. </div>
  63. </div>

searchUsers.jsp
  1. <%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%>
  2. <%@taglibprefix="c"uri="http://java.sun.com/jsp/jstl/core"%>
  3. <formid="pagerForm"method="post"action="user!searchUser.do">
  4. <inputtype="hidden"name="status"value="${param.status}">
  5. <inputtype="hidden"name="keywords"value="${param.keywords}"/>
  6. <inputtype="hidden"name="pageNum"value="1"/>
  7. <inputtype="hidden"name="pages.pageNo"value="${pages.pageNo}"/>
  8. <inputtype="hidden"name="pages.pageSize"value="${pages.pageSize}"/>
  9. </form>
  10. <divclass="pageHeader">
  11. <formrel="pagerForm"method="post"action="demo/database/dwzOrgLookup.html"onsubmit="returndwzSearch(this,'dialog');">
  12. <divclass="searchBar">
  13. <ulclass="searchContent">
  14. <li>
  15. <label>用户名称:</label>
  16. <inputclass="textInput"name="user.name"value="${user.name}"type="text">
  17. </li>
  18. </ul>
  19. <divclass="subBar">
  20. <ul>
  21. <li><divclass="buttonActive"><divclass="buttonContent"><buttontype="submit">查询</button></div></div></li>
  22. </ul>
  23. </div>
  24. </div>
  25. </form>
  26. </div>
  27. <divclass="pageContent">
  28. <tableclass="table"layoutH="140"width="100%">
  29. <thead>
  30. <tr>
  31. <thorderfield="orgName">序号</th>
  32. <thorderfield="orgNum">用户名称</th>
  33. <thorderfield="leader">用户电话</th>
  34. <thorderfield="creator">请选择</th>
  35. </tr>
  36. </thead>
  37. <tbody>
  38. <c:forEachvar="user"items="${pages.pages}"varStatus="status">
  39. <trtarget="sid_user"rel="${user.id}">
  40. <td>${status.count+(pages.pageNo-1)*pages.pageSize}</td>
  41. <td>${user.realName}</td>
  42. <td>${user.phone}</td>
  43. <td>
  44. <inputtype="checkbox"name="orgId"value="{id:'${user.id}',name:'${user.realName}'}"/>
  45. </td>
  46. </tr>
  47. </c:forEach>
  48. </tbody>
  49. </table>
  50. <divclass="panelBar">
  51. <divclass="pages">
  52. <span>显示</span>
  53. <selectclass="combox"name="numPerPage"onchange="navTabPageBreak({numPerPage:this.value})">
  54. <optionvalue="20">20</option>
  55. <optionvalue="50">50</option>
  56. <optionvalue="100">100</option>
  57. <optionvalue="200">200</option>
  58. </select>
  59. <span>条,共${pages.count}条</span>
  60. </div>
  61. <divclass="pagination"targetType="navTab"totalCount="${pages.count}"numPerPage="${pages.pageSize}"pageNumShown="10"currentPage="${pages.pageNo}"></div>
  62. </div>
  63. <divclass="formBar">
  64. <ul>
  65. <li><divclass="buttonActive"><divclass="buttonContent"><buttontype="button"multLookup="orgId">选择</button></div></div></li>
  66. <li><divclass="button"><divclass="buttonContent"><buttonclass="close"type="button">关闭</button></div></div></li>
  67. </ul>
  68. </div>
  69. </div>

suggest.jsp
  1. <%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%>
  2. <%@tagliburi="http://java.sun.com/jsp/jstl/core"prefix="c"%>
  3. [
  4. <c:forEachvar="u"items="${userList}"varStatus="status">
  5. {"id":"${u.id}","name":"${u.name}"}<c:iftest="${!status.last}">,</c:if>
  6. </c:forEach>
  7. ]

Action 代码
  1. packagecom.web.action;
  2. importjava.util.List;
  3. importjavax.annotation.Resource;
  4. importorg.springframework.context.annotation.Scope;
  5. importorg.springframework.stereotype.Controller;
  6. importcom.dwz.util.Pages;
  7. importcom.web.model.User;
  8. importcom.web.service.UserService;
  9. @Controller()
  10. @Scope("prototype")
  11. publicclassLookupActionextendsBaseAction{
  12. privateStringname;
  13. @Resource
  14. privateUserServiceuserService;
  15. privateList<User>userList;
  16. privatePagespages=newPages();
  17. privateUseruser;
  18. privateStringorderField;
  19. privateStringorderDirection;
  20. /**
  21. *用户提示补全
  22. *@return
  23. */
  24. publicStringsuggest(){
  25. userList=userService.listUser(name);
  26. returnRESULT;
  27. }
  28. /**
  29. *查询用户(单个)
  30. *@return
  31. */
  32. publicStringsearchUser(){
  33. pages=userService.searchUser(pages.getPageNo(),pages.getPageSize(),user,orderField,orderDirection);
  34. returnRESULT;
  35. }
  36. /**
  37. *查询用户(多个)
  38. *@return
  39. */
  40. publicStringsearchUsers(){
  41. pages=userService.searchUser(pages.getPageNo(),pages.getPageSize(),user,orderField,orderDirection);
  42. returnRESULT;
  43. }
  44. publicStringgetName(){
  45. returnname;
  46. }
  47. publicvoidsetName(Stringname){
  48. this.name=name;
  49. }
  50. publicvoidsetUserService(UserServiceuserService){
  51. this.userService=userService;
  52. }
  53. publicUserServicegetUserService(){
  54. returnuserService;
  55. }
  56. publicvoidsetUserList(List<User>userList){
  57. this.userList=userList;
  58. }
  59. publicList<User>getUserList(){
  60. returnuserList;
  61. }
  62. publicPagesgetPages(){
  63. returnpages;
  64. }
  65. publicvoidsetPages(Pagespages){
  66. this.pages=pages;
  67. }
  68. publicUsergetUser(){
  69. returnuser;
  70. }
  71. publicvoidsetUser(Useruser){
  72. this.user=user;
  73. }
  74. publicStringgetOrderField(){
  75. returnorderField;
  76. }
  77. publicvoidsetOrderField(StringorderField){
  78. this.orderField=orderField;
  79. }
  80. publicStringgetOrderDirection(){
  81. returnorderDirection;
  82. }
  83. publicvoidsetOrderDirection(StringorderDirection){
  84. this.orderDirection=orderDirection;
  85. }
  86. }

service 代码
  1. packagecom.web.service.impl;
  2. importjava.util.List;
  3. importjavax.annotation.Resource;
  4. importorg.springframework.stereotype.Service;
  5. importcom.dwz.util.Pages;
  6. importcom.web.dao.UserDao;
  7. importcom.web.model.User;
  8. importcom.web.service.UserService;
  9. @Service("userService")
  10. publicclassUserServiceImplimplementsUserService{
  11. @Resource
  12. privateUserDaouserDao;
  13. @Override
  14. publicUsergetUser(intid){
  15. returnuserDao.get(id);
  16. }
  17. @Override
  18. publicvoidaddUser(Useruser){
  19. userDao.insert(user);
  20. }
  21. @Override
  22. publicvoidupdateUser(Useruser){
  23. userDao.update(user);
  24. }
  25. @Override
  26. publicvoiddeleteUser(intid){
  27. userDao.delete(id);
  28. }
  29. @Override
  30. publicvoidreportUser(Useruser){
  31. userDao.insertOrUpdate(user,user.getId());
  32. }
  33. @Override
  34. publicPagessearchUser(intpageNo,intpageSize,Useruser,StringorderField,StringorderDirection){
  35. Stringwhere="where1=1";
  36. if(orderField!=null&&!orderField.trim().equals("")){
  37. if(orderDirection==null||orderDirection.trim().equals("")){
  38. orderDirection="asc";
  39. }
  40. where+="orderby"+orderField+""+orderDirection;
  41. }
  42. returnuserDao.listInPages(pageNo,pageSize,where);
  43. }
  44. @Override
  45. publicList<User>listUser(Stringname){
  46. Stringwhere="";
  47. if(name!=null&&!"".equals(name)){
  48. where="wherenamelike'%"+name+"%'";
  49. }
  50. returnuserDao.listQuery(where);
  51. }
  52. }
有几个注意的地方

lookupGroup 是一个组的意思,suggest 和 lookup 返回的字段,是根据名字进行查找的。如果指定的lookupGroup 为 test1,返回的字段是 userName,sex 那么就会超找

name 属性为 test1.userName , test1.sex 进行赋值 一般用的话 一个Model就可以是一个group ,这些东西看看源代码 dwz. database.js


poseField 进行代码提示时 已经输入的字 传到后台 一般进行 like 查找 poseField 设置的字段名称和action接收的属性名一直就行了的一样就可以了


suggestFields 是显示返回的字段

[

  1. {"id":"${u.id}","name":"${u.name}"}
]

返回是一个数组,显示的字段可以是多个 多个的话就 name-name-name 格式


suggestUrl 是提示的后台地址 可以看看我在Action中是怎么写的


查找带回没有什么难的地方,上面说的有些也是通用的

单个返回

  1. <aclass="btnSelect"href="javascript:$.bringBack({id:'${user.id}',name:'${user.realName}'})"title="查找带回">选择</a>

注意一下函数$.bringBack

  1. <buttontype="button"multLookup="orgId">选择</button>
批量带回的话注意上面的 multLookup 和 checkbox name 设置的一致就行了


批量带回的格式为 name,name,name,name 逗号间隔方式,我一般在后台进行 手动分隔一下。


转载请标明出处http://blog.csdn.net/jiweigang1/article/details/7829829

你可能感兴趣的:(suggest)