struts2 框架的新手。
我想以网格格式查看客户详细信息。
在网上搜索,最好的结果说使用 jqgrid。
我做了以下事情:
- 添加了必要的 Jar 文件,例如,jquery、json、jqgrid、convention...
- 使用 jsp 和 jqgrid 标签创建设计视图,
- 带有注释的 Cated 动作类...
它没有显示任何错误,但在部署或运行时它不起作用。
请任何人提供完整的工作示例供我参考
struts2 框架的新手。
我想以网格格式查看客户详细信息。
在网上搜索,最好的结果说使用 jqgrid。
我做了以下事情:
它没有显示任何错误,但在部署或运行时它不起作用。
请任何人提供完整的工作示例供我参考
你看过展示应用程序吗?这是一个完整的工作示例。也许下面的幻灯片给你一个开始。
http://www.slideshare.net/johannesgeppert1/introduction-into-struts2-jquery-grid-tags
Here is the Solution for your problem create a grid action which is shown as below
port java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opsbuds.rju.modules.usermgmt.bo.RoleManagementBo;
import com.opsbuds.rju.modules.usermgmt.bo.UserManagementBo;
import com.opsbuds.rju.modules.usermgmt.model.Role;
public class viewRolesGridAction extends ActionSupport implements
ServletRequestAware{
private List<String> module = new ArrayList<String>();
private Map session;
HttpServletRequest request;
private List<Role> roles;
private List<Role> roles1;
public List<Role> getRoles() {
return roles;
}
/**
* @return the roles1
*/
public List<Role> getRoles1() {
return roles1;
}
/**
* @param roles the roles to set
*/
public void setRoles(List<Role> roles) {
this.roles = roles;
}
public void setRoles1(List<Role> roles1) {
this.roles1 = roles1;
}
public List getModule() {
return module;
}
public void setModule(List module) {
this.module = module;
}
public void getModules() {
Map session = ActionContext.getContext().getSession();
session.get("module");
setModule((List) session.get("module"));
}
public List<Role> getGridModel() {
return gridModel;
}
public void setGridModel(List<Role> gridModel) {
this.gridModel = gridModel;
}
private List<Role> gridModel;
//get how many rows we want to have into the grid - rowNum attribute in the grid
private Integer rows = 0;
//Get the requested page. By default grid sets this to 1.
private Integer page = 0;
// sorting order - asc or desc
private String sord;
public Integer getPage() {
return page;
}
public void setPage(Integer page) {
this.page = page;
}
// get index row - i.e. user click to sort.
private String sidx;
// Search Field
private String searchField;
// The Search String
private String searchString;
// he Search Operation ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc']
private String searchOper;
// Your Total Pages
private Integer total = 0;
public Integer getRecords() {
return records;
}
public void setRecords(Integer records) {
this.records = records;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
// All Record
private Integer records = 0;
public Integer getRows() {
return rows;
}
public void setRows(Integer rows) {
this.rows = rows;
}
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
// @Actions( {
// @Action(value = "/viewRolestemp", results = {
// @Result(name = "success", type = "json")
// })
// })
public String execute()
{
getModules();
// rows=10;
System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxInside VIEWRolesAct execute method---------------------------------------------------------------------");
//
int to = (rows * page);
int from = to - rows;
//Count Rows (select count(*) from custumer)
//records = 9;
RoleManagementBo rolemgmt = new RoleManagementBo();
if (RoleAction.rolesinserttatus) {
System.out.println("role status");
addActionMessage(("Role saved successfully"));
RoleAction.rolesinserttatus = false;
}
if (RoleAction.roleupdatestatus) {
addActionMessage(("Role updated successfully"));
}
try{
roles = rolemgmt.viewRoles();
records=roles.size();
getModules();
RoleAction.rolesinserttatus = false;
RoleAction.roleupdatestatus = false;
}catch (Exception e) {
addActionError(getText(""));
}
to = (getRows() * getPage());
if (to > getRecords())
to = getRecords();
roles1 = new ArrayList();
for(int i=from;i<to;i++)
{
roles1.add(roles.get(i));
}
gridModel = roles1;
setTotal((int) Math.ceil((double) getRecords() / (double) getRows()));
return SUCCESS;
}
public String getJSON()
{
getModules();
return execute();
}
}
创建一个在这里显示的jsp
<s:url id="remoteurl" action="viewRolestemp" />
<sjg:grid id="gridtable" caption="Roles" dataType="json"
href="%{remoteurl}" pager="true" gridModel="gridModel"
rowList="10,15,20" rowNum="10" rownumbers="true"
width="800" navigator="true" navigatorView="false" navigatorDelete="false" navigatorAdd="false" navigatorEdit="false" navigatorSearch="false">
<sjg:gridColumn name="roleName" index="roleName" title="Role Name"
sortable="true" formatter="editrole" />
<sjg:gridColumn name="createdDate" index="createdDate"
title="Created Date" sortable="true" />
<sjg:gridColumn name="modificationDate" index="modificationDate"
title="Modified on" sortable="true" />
</sjg:grid>
在动作类中配置
<action name="viewRolestemp"
class="com.opsbuds.rju.modules.usermgmt.action.viewRolesGridAction">
<result name="input">/jsp/usermgmt/viewRoles.jsp</result>
<result name="success" type="json">>/jsp/usermgmt/viewRoles.jsp
</result>
<result name="error">/jsp/usermgmt/viewRoles.jsp</result>
</action>