`

《DWZ笔记四》URL变量替换

dwz 
阅读更多

 

来源:http://heavengate.blog.163.com/blog/static/2023810532012629091449/

 

在DWZ文档中,对URL的变量替换说明如下:

HTML扩展方式navTab, dialog, ajaxTodo 的url支持变量替换。例如:__URL__/edit/id/{xxx},大括号内的xxx就是变量名,主要功能是结合table组件一起使用,利用URL变量替换,对于解决数据的删除、编辑是非常方便的。

比如:删除、编辑使用了变量{sid_user}

<tbody>中<tr target="sid_user" rel="{$vo['id']}">

当选中一行时,tr上的rel值会自动替换到url变量中.

注意url变量名{sid_user}和tr的target="sid_user"保持一致.

具体的URL变量替换使用如下:

继续之前DWZ笔记二的例子,客户信息管理的界面如下:

《DWZ笔记四》URL变量替换 - heavengate - Heavengate的博客

 

界面代码如下:

<%@ page language="java"import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<base href="<%=basePath%>">

<%@taglib uri="/struts-tags"  prefix="s" %>

<!--分页的form-->

<form id="pagerForm" action="<%=basePath%>/admin/customer_main.action" method="post">
      <inputtype="hidden"name="pageNum"value="1"/><!--【必须】value=1可以写死-->
      <inputtype="hidden"name="numPerPage"value="${param.numPerPage}"/>-->
</form>

<divclass="pageHeader">

<!--查询的form-->
 <form  rel="pageForm"  onsubmit="return navTabSearch(this);"  action="<%=basePath%>/admin/customer_main.action" method="post">
 
 <divclass="searchBar">
  <ulclass="searchContent">
   <li>
    <label>我的客户:</label>
    <inputname="keywords"type="text"size="25"value="${param.keywords}"alt="请输入客户名"/>
   </li>
     </ul>
    <divclass="subBar">
   <ul>
    <li><divclass="buttonActive"><divclass="buttonContent"><buttontype="submit">检索</button></div></div></li>
    <li><aclass="button"href="demo_page6.html"target="dialog"mask="true"title="查询框"><span>高级检索</span></a></li>
   </ul>
  </div>
 </div>
 </form>
</div>

<divclass="pageContent">
 <divclass="panelBar">
  <ulclass="toolBar">
      <li><inputtype="checkbox"class="checkboxCtrl"group="ids"/>全选</li>
      <li><a title="确实要删除这些记录吗?" target="selectedTodo" rel="ids" postType="string" href="<%=basePath%>/admin/customer_deleteAll.action" class="delete"><span>批量删除</span></a></li>
   <li><a class="add" href="<%=basePath%>/admin/customer_addInput.jsp" target="navTab"><span>添加</span></a></li>
   <li><aclass="delete"href="customer_delete.action?customer.id={cid}"target="ajaxTodo"title="确定要删除吗?"><span>删除</span></a></li>
   <li><aclass="edit"href="customer_updateInput.action?id={cid}"target="navTab"><span>修改</span></a></li>
   <liclass="line">line</li>
   <li><aclass="icon"href="demo/common/dwz-team.xls"target="dwzExport"targetType="navTab"title="实要导出这些记录吗?"><span>导出EXCEL</span></a></li>
  </ul>
 </div>
 <tableclass="table"width="100%"layoutH="150">
  <thead>
   <tr>
                <thwidth="50">选择</th>
    <thwidth="120">序号</th>
    <th>客户昵称</th>
    <thwidth="100">客户名</th>
    <thwidth="150">客户类型</th>
    <thwidth="80"align="center">客户状态</th>
    <thwidth="80">客户邮箱</th>
    <thwidth="80">创建时间</th>
    <thwidth="80">上次登录时间</th>
    <thwidth="80">上次登录IP</th>
   </tr>
  </thead>
  <tbody>
  <s:iteratorvalue="customers"var="c">
     <trtarget="cid"rel="${c.id}">
         <td><inputtype="checkbox"name="ids"value="${c.id}"/></td>
         <td>${c.id}</td>
         <td>${c.cus_id}</td>
         <td>${c.cus_name}</td>
         <td><s:iftest='#c.cus_type=="2"'>普通客户</s:if><s:else>管理员</s:else></td>
         <td><s:iftest='#c.cus_isLock=="0"'>正常使用</s:if><s:else>用户锁定</s:else></td>
         <td>${c.cus_email}</td>
         <td>${c.cus_createtime}</td>
         <td>${c.last_logintime}</td>
         <td>${c.last_loginip}</td>
     </tr>
    </s:iterator>
  </tbody>
 </table>
 <divclass="panelBar">
  <divclass="pages">
   <span>显示</span>
   <selectclass="combox"name="numPerPage"onchange="navTabPageBreak({numPerPage:this.value})">
    <optionvalue="20">20</option>
    <optionvalue="10">10</option>
    <optionvalue="30">30</option>
    <optionvalue="500">50</option>
    <optionvalue="100">100</option>
   </select>
   <span>条,共${pager.totalCount}条</span>
  </div>
  <!--分页组件-->
  <divclass="pagination"targetType="navTab"totalCount="${pager.totalCount}"numPerPage="${pager.everyPage}"pageNumShown="10"currentPage="${pager.currentPage}"></div>

 </div>
 
</div>

在上述代码中,对于删除和编辑的按钮设置如下:

 <li>

<aclass="delete"href="customer_delete.action?customer.id={cid}"target="ajaxTodo"

title="确定要删除吗?"><span>删除</span></a>

</li>
<li><aclass="edit"href="customer_updateInput.action?id={cid}"target="navTab"><span>修改</span></a></li>

 
其中定义的XXX?id{cid}中的cid即为需要替换的变量,其具体定义在table中:

  <tableclass="table"width="100%"layoutH="150">
  <thead>
   <tr>
                <thwidth="50">选择</th>
    <thwidth="120">序号</th>
    <th>客户昵称</th>
    <thwidth="100">客户名</th>
    <thwidth="150">客户类型</th>
    <thwidth="80"align="center">客户状态</th>
    <thwidth="80">客户邮箱</th>
    <thwidth="80">创建时间</th>

    <thwidth="80">上次登录时间</th>
    <thwidth="80">上次登录IP</th>
   </tr>
  </thead>
  <tbody>
  <s:iteratorvalue="customers"var="c">
     <trtarget="cid"rel="${c.id}">
         <td><inputtype="checkbox"name="ids"value="${c.id}"/></td>
         <td>${c.id}</td>
         <td>${c.cus_id}</td>
         <td>${c.cus_name}</td>
         <td><s:iftest='#c.cus_type=="2"'>普通客户</s:if><s:else>管理员</s:else></td>
         <td><s:iftest='#c.cus_isLock=="0"'>正常使用</s:if><s:else>用户锁定</s:else></td>
         <td>${c.cus_email}</td>
         <td>${c.cus_createtime}</td>
         <td>${c.last_logintime}</td>
         <td>${c.last_loginip}</td>
     </tr>
   </s:iterator>
  </tbody>
 </table>


在这个table中,通过<s:iterator value="customers" var="c">,利用strut的标签,将后台的customer信息打印在页面中,同时进行关键设置<tr target="cid" rel="${c.id}">,当选中某一行时,rel="${c.id}"中的rel的值将自动替换到cid中,即通过target="cid"定义,也就是替换进删除和编辑的变量中。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics