Hi All,
I developed one application using struts2+Jpgrid(json)+Hibernate.I cann't able to send the values from server to browser.I debugging using firebox ,i am getting following values in server side.
[JSON]{"contactList":[{"birthDate":null,"cellNo":"9922009371","created":null,"emailId":"
kantha.lambu@gmail.com","firstName":"
test","id":1,"lastName":"test","website":null},{"birthDate":null,"cellNo":"222222222","created":null,"emailId":"
rao.lambu@gmail.com","firstName":"First","id":2,"lastName":"last","website":null}],"page":1,"records":2,"rows":10,"sidx":"id","sord":"desc","total":1}
MY JSP----------->
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>jqGrid Demo</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/ui-lightness/jquery-ui-1.7.1.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#contactList").jqGrid({
url:'index.action',
datatype: "json",
gridModel:"contactList",
mtype: 'POST',
colNames:['Id','firstName', 'lastName','cellNo'],
colModel :[
{name:'id', index:'id', width:80},
{name:'firstName', index:'firstName', width:200},
{name:'lastName', index:'lastName', width:200, align:'right'},
// {name:'emailId', index:'email_Id', width:200, align:'right'},
{name:'cellNo', index:'cell_No', width:200, align:'right'}
],
pager: jQuery('#pager2'),
rowNum:10,
rowList:[10,20,30],
sortname: 'id',
sortorder: "desc",
viewrecords: true,
caption: 'My first grid'
});
});
</script>
</head>
<body>
<div id="pager2" class="scroll" ></div>
</body>
</html>
Action....>
package net.viralpatel.contact.view;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import net.sf.json.JSONObject;
import net.viralpatel.contact.controller.ContactManager;
import net.viralpatel.contact.model.Contact;
import com.opensymphony.xwork2.ActionSupport;
public class ContactAction extends ActionSupport {
static final Logger logger = Logger.getLogger(ContactAction.class);
private static final long serialVersionUID = 9149826260758390091L;
private Contact contact;
private List<Contact> contactList;
//private int id;
//Get the requested page. By default grid sets this to 1.
private Integer page = 0;
// sorting order - asc or desc
private
String sord;
// get index row - i.e. user click to sort.
private String sidx;
private Integer rows = 0;
// Your Total Pages
private Integer total = 0;
// All Record
private Integer records = 0;
private ContactManager linkController;
public ContactAction() {
linkController = new ContactManager();
}
public String execute() {
/*if(null != contact) {
linkController.add(getContact());
}*/
logger.debug((new StringBuilder("Page ")).append(getPage()).append(" Rows ").append(getRows()).append(" Sorting Order ").append(getSord()).append(" Index Row :").append(getSidx()).toString());
contactList = linkController.list();
logger.debug("kanth"+contactList);
//System.out.println(contactList);
System.out.println(contactList.size());
setRecords(contactList.size());
Map map = new HashMap ();
map.put ("page", page);
map.put ("total", total);
List mapList = new ArrayList ();
Map cellMap = new HashMap ();
for (Iterator iterator = contactList.iterator (); iterator.hasNext ();) {
contact=(Contact)iterator.next();
cellMap.put ("id", contact.getId());
cellMap.put ("cell", new Object[] {contact.getId (),
contact.getFirstName(),contact.getLastName(),contact.getCellNo()});
mapList.add (cellMap);
map.put ("rows", mapList);
}
JSONObject object = new JSONObject();
object.putAll(map);
System.out.println (object.toString ());
total = Integer.valueOf((int)Math.ceil((double)records.intValue() / (double)rows.intValue()));
return SUCCESS;
}
public List<Contact> getContactList() {
return contactList;
}
/*public void setContact(Contact contact) {
this.contact = contact;
}*/
/**
* @return the page
*/
public Integer getPage() {
return page;
}
/**
* @param page the page to set
*/
public void setPage(Integer page) {
this.page = page;
}
/**
* @return the sord
*/
public String getSord() {
return sord;
}
/**
* @param sord the sord to set
*/
public void setSord(String sord) {
this.sord = sord;
}
/**
* @return the sidx
*/
public String getSidx() {
return sidx;
}
/**
* @param sidx the sidx to set
*/
public void setSidx(String sidx) {
this.sidx = sidx;
}
/**
* @return the rows
*/
public Integer getRows() {
return rows;
}
/**
* @param rows the rows to set
*/
public void setRows(Integer rows) {
this.rows = rows;
}
/**
* @return the total
*/
public Integer getTotal() {
return total;
}
/**
* @param total the total to set
*/
public void setTotal(Integer total) {
this.total = total;
}
/**
* @return the records
*/
public Integer getRecords() {
return records;
}
/**
* @param records the records to set
*/
public void setRecords(Integer records) {
this.records = records;
if(this.records.intValue() > 0 && rows.intValue() > 0)
{
total = Integer.valueOf((int)Math.ceil((double)this.records.intValue() / (double)rows.intValue()));
} else
{
total = Integer.valueOf(0);
}
}
}
Struts.xml-------->
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE
struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation"
value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.custom.i18n.resources"
value="ApplicationResources" />
<package name="default" extends="struts-default" namespace="/">
<result-types>
<result-type name="tiles"
class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<interceptors>
<interceptor name="mylogging"
class="net.viralpatel.contact.interceptor.MyLoggingInterceptor">
</interceptor>
<interceptor-stack name="loggingStack">
<interceptor-ref name="mylogging" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
<action name="login"
class="net.viralpatel.contact.view.LoginAction">
<interceptor-ref name="loggingStack"></interceptor-ref>
<result name="success" type="tiles">/tmu.tiles</result>
<result name="error">Login.jsp</result>
</action>
<action name="tmuAdmin"
class="net.viralpatel.contact.view.LoginAction" method="tabActions">
<interceptor-ref name="loggingStack"></interceptor-ref>
<result name="success" type="tiles">/tmuAdmin.tiles</result>
<result name="error">Login.jsp</result>
</action>
<action name="tmu"
class="net.viralpatel.contact.view.LoginAction" method="tabActions">
<interceptor-ref name="loggingStack"></interceptor-ref>
<result name="success" type="tiles">/tmu.tiles</result>
<result name="error">Login.jsp</result>
</action>
<action name="index"
class="net.viralpatel.contact.view.ContactAction">
<result name="success">/pages/index.jsp</result>
</action>
</package>
</struts>
Kindly give solution for these one