用于分页的Struts2中的DisplayTag
我想对我的struts2 web应用程序应用分页。当用户登录时,我会将他们重定向到主页,我希望在主页上使用用于分页的Struts2中的DisplayTag,struts2,displaytag,Struts2,Displaytag,我想对我的struts2 web应用程序应用分页。当用户登录时,我会将他们重定向到主页,我希望在主页上使用display标记显示分页中的所有用户 我已经做了研究,并最终将其集成到我的struts2中,但是当我在登录后运行代码时,它会显示消息找不到要显示的内容 当我在struts1.3中做了同样的事情,从中获取示例时,它是有效的。 我已将以下JAR文件复制到我的lib文件夹中: commons-logging.jar commons-lang.jar commons-collections.jar
display
标记显示分页中的所有用户
我已经做了研究,并最终将其集成到我的struts2中,但是当我在登录后运行代码时,它会显示消息找不到要显示的内容
当我在struts1.3中做了同样的事情,从中获取示例时,它是有效的。
我已将以下JAR文件复制到我的lib
文件夹中:
commons-logging.jar
commons-lang.jar
commons-collections.jar
commons-beanutils.jar
displaytag-1.2.jar
我还将displaytag.tld
和struts-2.17.dtd
复制到我的web inf
文件夹中
下面是我的代码:
myprofile.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
</head>
<body>
<div id="wrapper">
<div id="steps">
<fieldset class="step">
<legend>Profile
</legend>
<display:table id="data" name="list" requestURI="/display.action" pagesize="1" >
<display:column sortable="true">
<p>
<label for="username">User Name</label>
<input id="username" name="username" value="<s:property value="firstName" />" disabled="disabled"/>
</p>
<p>
<label for="email">Father Name</label>
<input id="email" name="email" value="<s:property value="lastName"/>" disabled="disabled" />
</p>
<p>
<label for="password">Age</label>
<input name="password" value="<s:property value="dob"/>" disabled="disabled"/>
</p>
<p>
<label for="address">Address</label>
<input name="address" value="<s:property value="emailID"/>" disabled="disabled"/>
</p>
</fieldset>
</div>
</display:column>
</display:table>
</div>
</div>
</body>
</html>
SearchDB.java
//code to get records. their is no problem here because it is taking records out from db fine.
我不确定,但我猜是
requestURI
和displaytag
中的name属性,因为在上面链接的示例中,它们使用的是name=“sessionScope.UserForm.userList”
。有人能告诉我哪里做错了吗 您可能已经解决了这个问题,但无论如何……请尝试像这样使用OGNL:
<input id="username" name="username" value="%{data.firstName}" disabled="disabled"/>
它直接使用用户属性的getter。顺便说一下,我不确定你的残疾标签。您可能应该改为使用readonly。您已经为显示标记设置了记录总数,如
<display:table id="data" name="lstEntities"
sort="external" uid="row" htmlId="rowid" class="tborder"
style="width:100%" excludedParams="*"
pagesize="${pageCriteria.recordsPerPage}" partialList="true"
size="${pageCriteria.totalRecords}" export="false"
requestURI="XXX.action">
public class PaginationCriteria implements Cloneable, CommonConstants,
Serializable {
/**
* Holds the Unie value of Class.
*/
private static final long serialVersionUID = 8047568459658871831L;
/**
* Stores cache Mode.
*/
private boolean cached;
/**
* Stores current page number in the user screen.
*/
private int currentPage;
/**
* Holds the Name of the attribute in Entity to be unique.
*/
private String distinctRootEntityName;
/**
* Stores the information about no of entities to be fetched.
*/
private boolean fetchAll;
/**
* Stores the information about no. of records to be fetched.
*/
private int recordsPerPage;
/**
* Stores the secondary sort column of the entity.
*/
private String secondarySortBy;
/**
* Stores the Sort column of the entity.
*/
private String sortBy;
/**
* Stores the sort order of the entity.
*/
private boolean sortDescending;
/**
* Stores total no. of records.
*/
private int totalRecords;
//Getters and setters of this properties
}
希望能有帮助。如果您需要任何其他信息,请告诉我。我对jsp开头的taglib指令感兴趣。我对struts1的引用和标记这个struts2感到非常困惑。我用taglib指令更新我的问题check it@QuaternionI不使用display标记,所以我只是猜测一下。我猜显示标签使用常规EL,而Struts2使用OGNL。所以显示表中的“name”属性并没有将“list”推到堆栈的顶部,所以s2标记不知道它们正在处理什么。。。尝试以下两件事:在s2属性中,而不是在“firstName”中写入“list.firstName”(如果出现了什么,那么我们知道我说的是真的),然后尝试将所有属性标记替换为“${fieldName}”(没有角度标记!只使用该表达式[其中fieldName当然是字段名],然后查看是否发生了什么)
//code to get records. their is no problem here because it is taking records out from db fine.
<input id="username" name="username" value="%{data.firstName}" disabled="disabled"/>
<display:table id="data" name="lstEntities"
sort="external" uid="row" htmlId="rowid" class="tborder"
style="width:100%" excludedParams="*"
pagesize="${pageCriteria.recordsPerPage}" partialList="true"
size="${pageCriteria.totalRecords}" export="false"
requestURI="XXX.action">
public class PaginationCriteria implements Cloneable, CommonConstants,
Serializable {
/**
* Holds the Unie value of Class.
*/
private static final long serialVersionUID = 8047568459658871831L;
/**
* Stores cache Mode.
*/
private boolean cached;
/**
* Stores current page number in the user screen.
*/
private int currentPage;
/**
* Holds the Name of the attribute in Entity to be unique.
*/
private String distinctRootEntityName;
/**
* Stores the information about no of entities to be fetched.
*/
private boolean fetchAll;
/**
* Stores the information about no. of records to be fetched.
*/
private int recordsPerPage;
/**
* Stores the secondary sort column of the entity.
*/
private String secondarySortBy;
/**
* Stores the Sort column of the entity.
*/
private String sortBy;
/**
* Stores the sort order of the entity.
*/
private boolean sortDescending;
/**
* Stores total no. of records.
*/
private int totalRecords;
//Getters and setters of this properties
}
/**
* Fills the Sort column, order, page number to be retrieved.
*
* @param tableId -
* Display tag table Id to retrieve the Sort column, order, page
* number
* @param defaultOrderCoulmn -
* If no parameter passed for sorting default order column will be
* applied.
*/
protected void fillPaginationInfo(final String tableId,
final String defaultOrderCoulmn, final String secondarySortColumn) {
BaseAction.LOGGER.debug(BaseAction.LOG_PREFIX
+ "calling fillPaginationInfo param: tableId :" + tableId
+ "\ndefaultOrderCoulmn:" + defaultOrderCoulmn);
this.getPageCriteria().setCurrentPage(
this.getPageNumber(this.getHttpRequest(), tableId));
String orderBy = this.getSortColumn(this.getHttpRequest(), tableId);
this.getPageCriteria().setSortBy(
orderBy == null || orderBy.equals("null") ? defaultOrderCoulmn
: orderBy);
this.getPageCriteria().setSortDescending(
this.getSortOrderDesc(this.getHttpRequest(), tableId));
if (secondarySortColumn != null)
this.getPageCriteria().setSecondarySortBy(secondarySortColumn);
BaseAction.LOGGER.debug(BaseAction.LOG_PREFIX
+ "done fillPaginationInfo");
}