当我在动作类中实现模型驱动时,我的Web应用程序没有加载数据。删除modeldriven时它工作正常。 行动类:
package action;
import action.UserBean;
import java.util.ArrayList;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import service.OrganisationBo;
import model.AtDivision;
import model.AtOrganisation;
public class OraganisationAction extends ActionSupport implements ModelDriven<UserBean> {
private String uname;
private String passwd;
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;
//Your result List
private List<UserBean> 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;
private boolean loadonce = false;
// All Record
private Integer records = 0;
private String includepage;
private List<UserBean> myList;
private String oper;
private String id;
private String contact;
private String country;
UserBean ubs = new UserBean();
private AtOrganisation org = new AtOrganisation();
private AtDivision div = new AtDivision();
private List<AtOrganisation> orglist = new ArrayList<AtOrganisation>();
OrganisationBo orgBo;
private String aoId;
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getPasswd() {
return passwd;
}
public void setPasswd(String passwd) {
this.passwd = passwd;
}
public String getSidx() {
return sidx;
}
public void setSidx(String sidx) {
this.sidx = sidx;
}
public String getSearchField() {
return searchField;
}
public void setSearchField(String searchField) {
this.searchField = searchField;
}
public String getSearchString() {
return searchString;
}
public void setSearchString(String searchString) {
this.searchString = searchString;
}
public String getSearchOper() {
return searchOper;
}
public void setSearchOper(String searchOper) {
this.searchOper = searchOper;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public List<UserBean> getGridModel() {
return gridModel;
}
public void setGridModel(List<UserBean> gridModel) {
this.gridModel = gridModel;
}
public Integer getRows() {
return rows;
}
public void setRows(Integer rows) {
this.rows = rows;
}
public Integer getPage() {
return page;
}
public void setPage(Integer page) {
this.page = page;
}
public String getSord() {
return sord;
}
public void setSord(String sord) {
this.sord = sord;
}
public boolean isLoadonce() {
return loadonce;
}
public void setLoadonce(boolean loadonce) {
this.loadonce = loadonce;
}
public Integer getRecords() {
return records;
}
public void setRecords(Integer records) {
this.records = records;
}
public String getIncludepage() {
return includepage;
}
public void setIncludepage(String includepage) {
this.includepage = includepage;
}
public List<UserBean> getMyList() {
return myList;
}
public void setMyList(List<UserBean> myList) {
this.myList = myList;
}
public String getOper() {
return oper;
}
public void setOper(String oper) {
this.oper = oper;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getContact() {
return contact;
}
public void setContact(String contact) {
this.contact = contact;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public List<AtOrganisation> getOrglist() {
return orglist;
}
public void setOrglist(List<AtOrganisation> orglist) {
this.orglist = orglist;
}
public String getAoId() {
return aoId;
}
public void setAoId(String aoId) {
this.aoId = aoId;
}
public void setOrgBo(OrganisationBo orgBo) {
this.orgBo = orgBo;
}
public AtDivision getDiv() {
return div;
}
public void setDiv(AtDivision div) {
this.div = div;
}
public AtOrganisation getOrg() {
return org;
}
public void setOrg(AtOrganisation org) {
this.org = org;
}
public String execute() throws Exception {
myList = DAO.buildList();
setRecords(DAO.count());
int to = (getRows() * getPage());
int from = to - getRows();
if (to > getRecords()) {
to = getRecords();
}
if (loadonce) {
setGridModel(myList);
} else {
if (searchString != null && searchOper != null && !searchString.equals("") && !searchOper.equals("")) {
System.out.println("Searching within Database");
if (searchOper.equalsIgnoreCase("cn")) {
// setGridModel(DAO.findbyName(searchString));
}
} else {
System.out.println("Not Searching Anywhere");
//setGridModel(DAO.find(from, to));
System.out.println("dili 4444");
setGridModel(myList);
}
}
total = (int) Math.ceil((double) getRecords() / (double) getRows());
System.out.println("tot " + total);
System.out.println(gridModel.size());
return SUCCESS;
}
@Override
public UserBean getModel() {
return ubs;
}
}
Struts.xml:
<package name="default" extends="struts-default,json-default">
<action name="gridaction" class="action.OraganisationAction" >
<result name="success" type="json"/>
</action>
</package>
</struts>
index.jsp:
<%--
Document : index
Created on : 15 Nov, 2011, 11:45:45 PM
Author : XCoder
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib prefix="sj" uri="/struts-jquery-tags" %>
<%@taglib prefix="sjg" uri="/struts-jquery-grid-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<sj:head jquerytheme="start" jqueryui="true"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<s:url id="remoteurl" action="gridaction"/>
<sjg:grid
id="sjgrid"
caption="Grid Model"
dataType="json"
href="%{remoteurl}"
pager="true"
rowList="10,20,100"
rowNum="5"
navigator="true"
width="999"
navigatorSearchOptions="{sopt:['eq','ne','lt','gt']}"
navigatorAddOptions="{height:280,reloadAfterSubmit:true}"
navigatorEditOptions="{height:280,reloadAfterSubmit:false}"
navigatorEdit="false"
navigatorView="false"
navigatorDelete="true"
navigatorDeleteOptions="{height:280,reloadAfterSubmit:true}"
gridModel="gridModel"
editurl="%{editurl}"
editinline="true"
onSelectRowTopics="rowselect"
>
<sjg:gridColumn name="iduser" formatter="integer" title="iduser" key="true" hidden="true"/>
<sjg:gridColumn name="uname" title="Username" editable="true" align="center"
editrules="{required:true}"
/>
<sjg:gridColumn name="passwd" title="Password" editable="true" align="center"
editrules="{required:true}"
/>
<sjg:gridColumn name="country" title="Country" editable="true" align="center"
edittype="select"
editoptions="{dataUrl:'%{selecturl}'}"
/>
<sjg:gridColumn name="contact" title="Contact No" editable="true" align="center"
editrules="{required:true,number:true,integer:true}"
/>
</sjg:grid>
</body>
</html>
我们不能实现用jqgrid驱动的模型,否则我的代码错了?
编辑: 只需弄清楚modeldriven可以正常使用旧的lib set
但是当我将项目更新为struts网格的新版本时,不填充数据。新的lib集如下:
任何人都知道这里发生了什么?