0

I am trying to show the data from struts2 action class into JQuery Grid. but when i try to achieve that, I am not even getting the Grid, it is just showing the JSON string as output, as shown below, tried all the other answers posted here but no luck..:(

{

"dummyData": [
    {
        "email": "ABC",
        "name": "DEF"
    }
],
"page": null,
"records": 1,
"resDetailObj": {
    "email": "ABC",
    "name": "DEF"
},
"rows": 0,
"searchField": null,
"searchOper": null,
"searchString": null,
"sidx": null,
"sord": null,
"total": 2147483647

}

I am using struts2-jquery-grid-plugin-3.5.1.jar, struts2-jquery-plugin-3.2.1.jar and struts2-json-plugin-2.1.8.jar

My jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org     /TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
<html>

<h1>In JQueryGrid</h1>
<head>
    <sj:head jqueryui="true" jquerytheme="redmond"/>
</head>
<body>
    <s:url var="remoteurl" action="grid"/>
    <sjg:grid
        id="mygrid"
        caption="My Details"
        dataType="json"
        href="%{remoteurl}"
        pager="true"
        gridModel="dummyData"

     >
        <sjg:gridColumn name="name" index="name" title="Name" 
        sortable="true"/>

        <sjg:gridColumn name="email" index="email" title="Email"
        sortable="true"/>

    </sjg:grid>
</body>


</html>

and my struts.xml file is

<package name="JQueryGrid" namespace="/" extends="struts-default">              
    <action name="grid class="com.digi.crystal.resourceutilization.actions.GridAction">
        <result name="success" type="json">
            /JqueryGrid.jsp
        </result>
    </action>
</package>

and finally my Action class is

public class GridAction extends ActionSupport
{
private List<CResourceDetails> dummyData;
private Integer rows=0;
private Integer page;
private String sord;
private String sidx;
private String searchField;
private String searchString;
private String searchOper;
private Integer total;
private Integer records; 


private CResourceDetails resDetailObj = new CResourceDetails();
public GridAction()
{

}

public String execute()
{

    List<CResourceDetails> temp = new ArrayList<CResourceDetails>();
    resDetailObj.setEmail("ABC");
    resDetailObj.setName("DEF");
    temp.add(resDetailObj);

    setDummyData(temp);
    System.out.println("The temp is:"+"in execute"+dummyData.size()+","+rows);          
     setRecords(temp.size());
     total =(int) Math.ceil((double)records / (double)rows);
     System.out.println("the total is:"+total/1000000000);
    return Action.SUCCESS;
}
// getters and setters of attributes

Here CResourceDetails is nothing but a plain POJO, with name and email.

If anyone could help me with this grid, that would be a great favor to me.

Thanks a lot in advance,

C.S.Siddartha

Siddarth
  • 33
  • 8

2 Answers2

0

I think you are accessing directly to the action grid:

http://localhost:8080/JQueryGrid/grid.action

Try to access to the jsp:

http://localhost:8080/JQueryGrid/JqueryGrid.jsp

The grid will then call the action and retrive the result.

Joan
  • 427
  • 3
  • 6
  • Thanks a lot for reply, but if i try, doing it the way you said, i just getting the H1 tag, and not even empty grid is getting displayed..:( – Siddarth Apr 04 '13 at 11:53
  • You have to define the result type JSON in your struts.xml. In the action definition, the JSP is not needed. And in the JSP, I belive that the correct url definition is : – Joan Apr 04 '13 at 12:42
  • Again thanks a lot for taking your time helping me, but even if i do that there is no change in what i am getting..:( – Siddarth Apr 05 '13 at 03:26
  • Did the action execute? Can see the system.out in the console? – Joan Apr 05 '13 at 08:25
  • Yes i can see the system.out in the console...:( – Siddarth Apr 05 '13 at 08:45
  • I check the example: [link](https://code.google.com/p/struts2-jquery/wiki/GridTag) In order to enable JSON results you shoud extend your package in struts.xml from json-default : – Joan Apr 05 '13 at 10:30
  • thanks a lot for your reply, i have even tried that too, but not luck – Siddarth Apr 05 '13 at 12:27
0

Siddarth first write an action in struts with result mapping only to the JSP page containing the grid And then wirte ur action for grid with only json

<package name="JQueryGrid" namespace="/" extends="struts-default,json-default">
 <action name="opengridJSP" class="com.digi.crystal.resourceutilization.actions.GridAction" method ="SomeMethod">
    <result name="success">/JqueryGrid.jsp</result>
</action>

<action name="grid class="com.digi.crystal.resourceutilization.actions.GridAction">
    <result name="success" type="json"/>
</action>
</package>
Manjunath
  • 715
  • 1
  • 7
  • 17