displaytag 相关
生活随笔
收集整理的這篇文章主要介紹了
displaytag 相关
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、獲取某列(如: id)的值
struts 2:
<display:table name="usersInfo" id="tabrow" pagesize="${pageSize}" requestURI="web/sys/userManager/UserQuery.action" class="scroll_its" style="width:680px;"><display:caption><thead><tr><th style="text-align:center;width:7%;"><input type="checkbox" name="box" οnclick="selcheck()" /></th><th style="text-align:center;width:20%;"><s:text name="web.usermanager.userid"/></th> <th style="text-align:center;width:20%;"><s:text name="web.usermanager.username"/></th><th style="text-align:center;width:20%;"><s:text name="web.login.password"/></th><th style="text-align:center;width:33%;"><s:text name="web.management.remark"/></th></tr></thead></display:caption> <display:column title='' style="text-align:center;width:7%;"><s:iterator value="seluser" status="status"> <s:if test="seluser[#status.index]==#attr.tabrow.pcUsrId"><s:set name="Selbool" value="1" /> </s:if> </s:iterator><s:if test="#Selbool==1"><s:checkbox name="seluser" id="seluser" theme="simple" value="true" fieldValue="%{#attr.tabrow.pcUsrId}" οnclick="changeButtonStatus();"></s:checkbox></s:if><s:else> <s:checkbox name="seluser" id="seluser" theme="simple" value="false" fieldValue="%{#attr.tabrow.pcUsrId}" οnclick="changeButtonStatus();"></s:checkbox></s:else> <s:set name="Selbool" value="0" /> </display:column><display:column property="pcUsrId" titleKey="web.usermanager.userid" style="text-align:left;width:20%;" escapeXml="true" /><display:column property="pcUsrNm" titleKey="web.usermanager.username" style="text-align:left;width:20%;" escapeXml="true" /><display:column property="pcUsrPw" titleKey="web.login.password" style="whitespace: nowrap;width:20%;" escapeXml="true" maxLength="200" /><display:column property="note" titleKey="web.management.remark" style="text-align:center;width:33%;" /> </display:table>
關鍵代碼:
<s:if test="seluser[#status.index]==#attr.tabrow.pcUsrId"> fieldValue="%{#attr.tabrow.pcUsrId}"JSTL: <display:table id="row" name="mylist"><display:column title="row number" ><c:out value="${row_rowNum}"/></display:column><display:column title="name" ><c:out value="${row.first_name}"/><c:out value="${row.last_name}"/></display:column></display:table>
2、通過<display:table ?id="xxxx"> 的id 屬性構造和獲取其傳遞當前頁的參數名稱(適合 displaytag 自動分頁方式) /*** 通過表格ID名稱取得PAGE的字符串* @param id* @return*/public static String getPageParamName(String id){return new org.displaytag.util.ParamEncoder(id).encodeParameterName(org.displaytag.tags.TableTagParameters.PARAMETER_PAGE);}
3、自定義實現分頁,傳遞頁面的參數名默認為( page )
第一步:實現?PaginatedList 接口的類
package jp.co.snjp.kddi.web.util;import java.util.List;import org.displaytag.pagination.PaginatedList; import org.displaytag.properties.SortOrderEnum;public class PageList implements PaginatedList {private List list; /** 每頁的列表 **/private int pageNumber = 1 ; /** 當前頁碼 **/private int objectsPerPage = 15 ; /** 每頁記錄數 page size **/private int fullListSize = 0 ; /** 總記錄數 **/private String sortCriterion;private SortOrderEnum sortDirection;private String searchId;public void setFullListSize(int fullListSize) {this.fullListSize = fullListSize;}public void setList(List list) {this.list = list;}public void setObjectsPerPage(int objectsPerPage) {this.objectsPerPage = objectsPerPage;}public void setPageNumber(int pageNumber) {this.pageNumber = pageNumber;}public void setSearchId(String searchId) {this.searchId = searchId;}public void setSortCriterion(String sortCriterion) {this.sortCriterion = sortCriterion;}public void setSortDirection(SortOrderEnum sortDirection) {this.sortDirection = sortDirection;}public int getFullListSize() {return fullListSize;}public List getList() {return list;}public int getObjectsPerPage() {return objectsPerPage;}public int getPageNumber() {return pageNumber;}public String getSearchId() {return searchId;}public String getSortCriterion() {return sortCriterion;}public SortOrderEnum getSortDirection() {return sortDirection;}}第二步:提供一個實現分頁的Action 的基類 package jp.co.snjp.kddi.web.util;import jp.co.snjp.kddi.web.login.form.LoginUserForm;/*** 所有需要分頁操作的action 的基類* @author GongQiang**/ public class PageListAction extends BaseAction {private static final long serialVersionUID = 1L;/** 分頁顯示用戶信息的 pagelist **/protected PageList pageList; /** 總頁數 **/protected int totalPage; /** 每頁顯示記錄條數 **/protected int pageSize; public int getTotalPage() {return totalPage;}public void setTotalPage(int totalPage) {this.totalPage = totalPage;}public PageList getPageList() {return pageList;}public void setPageList(PageList pageList) {this.pageList = pageList;}public int getPageSize() {return 5;}public void setPageSize(int pageSize) {this.pageSize = pageSize;}@Overridepublic String executeSCH() throws Exception {// TODO Auto-generated method stubreturn null;}/*** 執行查詢操作的當前頁* @return** Date :2011-11-28* Author :GongQiang*/public int getPage(){String pageStr = request.getParameter( "page" );int page;try {page = Integer.parseInt( pageStr );} catch (NumberFormatException e) {page = 1;}return page;}/*** 執行刪除、修改操作的當前頁* @return** Date :2011-11-28* Author :GongQiang*/public int getPageHidden(){String pageStr = request.getParameter( "page_hidden" );int page;try {page = Integer.parseInt( pageStr );} catch (NumberFormatException e) {page = 1;}return page;}/*** 在查詢頁面提供一個 page_hidden 參數* 提供給 刪除、修改操作獲取* Date :2011-11-29* Author :GongQiang*/public void savePageHiddenInRequest(){request.setAttribute( "page_hidden", getPage() );}/*** 當前用戶的 companyId* @return** Date :2011-11-28* Author :GongQiang*/public String getCompanyId(){LoginUserForm loginUserForm = ( LoginUserForm )session.getAttribute( "userList" );return loginUserForm.getCompanyid();} }
第三步:實際分頁的 Action,完成PageListAction 中 pageList 和 totalPage 的初始化。(具體示例 ?...略)
第四步:頁面顯示
<display:table name="pageList" id="tabrow" partialList="true" size="${totalPage}" requestURI="/bpp/web/sys/userManager/UserQuery.action" class="scroll_its" style="width:680px;"excludedParams="page_hidden search __checkbox_seluser seluser box"><display:caption><thead><tr><th style="text-align:center;width:7%;"><input type="checkbox" name="box" οnclick="selcheck()" /></th><th style="text-align:center;width:20%;"><s:text name="web.usermanager.userid"/></th> <th style="text-align:center;width:20%;"><s:text name="web.usermanager.username"/></th><th style="text-align:center;width:20%;"><s:text name="web.login.password"/></th><th style="text-align:center;width:33%;"><s:text name="web.management.remark"/></th></tr></thead></display:caption> <display:column title='' style="text-align:center;width:7%;"><s:iterator value="seluser" status="status"> <s:if test="seluser[#status.index]==#attr.tabrow.pcUsrId"><s:set name="Selbool" value="1" /> </s:if> </s:iterator><s:if test="#Selbool==1"><s:checkbox name="seluser" id="seluser" theme="simple" value="true" fieldValue="%{#attr.tabrow.pcUsrId}" οnclick="changeButtonStatus();"></s:checkbox></s:if><s:else> <s:checkbox name="seluser" id="seluser" theme="simple" value="false" fieldValue="%{#attr.tabrow.pcUsrId}" οnclick="changeButtonStatus();"></s:checkbox></s:else> <s:set name="Selbool" value="0" /> </display:column><display:column property="pcUsrId" titleKey="web.usermanager.userid" style="text-align:left;width:20%;" escapeXml="true" /><display:column property="pcUsrNm" titleKey="web.usermanager.username" style="text-align:left;width:20%;" escapeXml="true" /><display:column property="pcUsrPw" titleKey="web.login.password" style="whitespace: nowrap;width:20%;" escapeXml="true" maxLength="200" /><display:column property="note" titleKey="web.management.remark" maxLength="60" style="text-align:left;width:33%;white-space:nowrap;" escapeXml="true"/> </display:table>
最主要代碼: <display:table name="pageList" id="tabrow" partialList="true" size="${totalPage}"
4、部分屬性說明
partialList
能否顯示集合的一部分,有效的值是true或false
size
當partialList為true時才能使用,是寫入一個整型對象,它是包含總數據集大小的,要用方法給整數賦予屬性
maxLength
表格里的值截斷,與顯示空白.
<display:column property="longDescription" maxLength="10" style="whitespace: nowrap;"/>
sort="external"
告訴DisplayTag傳入的數據集已經由外部程序排好序了..
defaultsort="1"
說明默認是升序(Descending is 2, Ascending is 1);
partialList="true"
說明部分裝入數據;
pagesize="20"
每頁顯示記錄數;
size="resultSize"
顯示記錄的總條數(此參數結合PageSize,使得表格在只拿到某一頁的完整數據的同時,可以知道會有多少頁,并將其他的頁數也列舉出來,當用戶實際翻頁時才去獲取當頁數據).
總結
以上是生活随笔為你收集整理的displaytag 相关的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: app store 服务器维护,AppS
- 下一篇: Guava RateLimiter限流原