Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7278069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:49:30+00:00 2026-05-28T22:49:30+00:00

I’m using struts2-jquery grid. gridmodel in my action class is getting updated correctly. But,

  • 0

I’m using struts2-jquery grid.

gridmodel in my action class is getting updated correctly. But, nothing is getting displayed on the grid.

struts.xml

<struts>

    <package name="default" namespace="/searchAndUpdate" extends="struts-default,json-default">

        <action name="listUsers" class="com.pilot.web.action.ListUsers" method="getJSON">
            <result name="success">/jsp/userList.jsp</result>
            <result name="input">/jsp/userList.jsp</result>
        </action>
</package> 

userList.jsp

<%@ page contentType="text/html; charset=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 XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<sj:head jqueryui="true" jquerytheme="redmond"/>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
</head>
<body>
<h3>Application Users</h3>
<s:actionerror/>
<s:actionmessage/>
<s:url id="remoteurl" action="/searchAndUpdate/listUsers"/>
    <sjg:grid
        id="gridtable" 
        caption="Application Users" 
        dataType="json" 
        href="%{remoteurl}" 
        pager="true" 
        gridModel="gridModel" 
        rowList="10,15,20" 
        rowNum="15" 
        rownumbers="true" 
        resizable="true" 
        viewrecords="true" 
    >
        <sjg:gridColumn name="id" index="id" title="Id" formatter="integer" sortable="false"/>
        <sjg:gridColumn name="userName" index="userName" title="User Name" sortable="true"/>
        <sjg:gridColumn name="fullName" index="fullName" title="Full Name" sortable="false"/>
        <sjg:gridColumn name="email" index="email" title="EMail" sortable="false"/>
    </sjg:grid>
</body>
</html>

ListUsers.java

package com.pilot.web.action;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionSupport;
import com.oxxo.pilot.backend.jdbc.dao.impl.User;


public class ListUsers extends ActionSupport {
        private static final long serialVersionUID = 1L;
        private List<User> 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;
        // Your Total Pages
        private Integer total = 0;
        // All Records
        private Integer records = 0;
        // sorting order - asc or desc
        private String sord;
        // get index row - i.e. user click to sort.
        private String sidx;
        public String getAllApplicationData() {
                List<User> users = userListFromDb();
                if (users != null && getSord() != null
                                && getSord().equalsIgnoreCase("asc")) {
                        Collections.sort(users, null);
                }
                if (getSord() != null && "desc".equalsIgnoreCase(getSord())) {
                        Collections.sort(users, null);
                        Collections.reverse(users);
                }
                setRecord(users.size());
                int to = (getRows() * getPage());
                if (to > getRecord())
                        to = getRecord();

                setGridModel(users);
                setTotal((int) Math.ceil((double) getRecord() / (double) getRows()));
                System.out.println("Total is : " + getTotal());
                System.out.println("Record is : " + getRecord());
                for(User user: users){
                        System.out.println(user.getUserName() + ", " + user.getFullName() + ", " + user.getEmail());
                }
                if (hasActionMessages() || hasActionErrors()) {
                        return INPUT;
                }
                return SUCCESS;
        }

        private List<User> userListFromDb() {
           // MOCKED List for now
                List<User> users = new ArrayList<User>();
                User user1 = new User();
                user1.setId(1);
                user1.setUserName("user1");
                user1.setFullName("User ABC");
                user1.setEmail("user1@email.com");

                User user2 = new User();
                user2.setId(1);
                user2.setUserName("user2");
                user2.setFullName("User DEF");
                user2.setEmail("user2@email.com");

                users.add(user1);
                users.add(user2);
                return users; // TODO FETCH LIST OF USERS FROM DB
        }

        public String getJSON() {
                System.out.println("here in getJSON");
                return getAllApplicationData();
        }

        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 Integer getTotal() {
                return total;
        }

        public void setTotal(Integer total) {
                this.total = total;
        }

        public Integer getRecord() {
                return records;
        }

        public void setRecord(Integer records) {
                this.records = records;
                if (this.records > 0 && this.rows > 0) {
                        this.total = (int) Math.ceil((double) this.records
                                        / (double) this.rows);
                } else {
                        this.total = 0;
                }
        }
        public List<User> getGridModel() {
                return gridModel;
        }
        public void setGridModel(List<User> gridModel) {
                this.gridModel = gridModel;
        }
        public String getSord() {
                return sord;
        }
        public void setSord(String sord) {
                this.sord = sord;
        }
        public String getSidx() {
                return sidx;
        }
        public void setSidx(String sidx) {
                this.sidx = sidx;
        }
        public void setSearchField(String searchField) {
        }

        public void setSearchString(String searchString) {
        }

        public void setSearchOper(String searchOper) {
        }

        public void setLoadonce(boolean loadonce) {
        }
        public void setSession(Map<String, Object> session) {
        }
}

I did refer to the solution on struts2 jquery grid data not load?

But that solution did not work. Instead of data getting displayed on the grid, it prompted to save the file & that file contained the following info:

{“JSON”:”success”,”gridModel”:[{“email”:”user1@email.com”,”fullName”:”User ABC”,”id”:1,”userName”:”user1″},{“email”:”user2@email.com”,”fullName”:”User DEF”,”id”:1,”userName”:”user2″}],”page”:0,”record”:2,”rows”:0,”sidx”:null,”sord”:null,”total”:2147483647}*

As per my understanding row & page are automatically handled by the plugin. But as per the json data above they are not getting incremented. Hard-coded them to the size of the gridmodel and the json data I got is:

{“JSON”:”success”,”allApplicationData”:”success”,”gridModel”:[{“email”:”user1@email.com”,”fullName”:”User ABC”,”id”:1,”userName”:”user1″},{“email”:”user2@email.com”,”fullName”:”User DEF”,”id”:1,”userName”:”user2″}],”page”:1,”record”:2,”rows”:2,”sidx”:null,”sord”:null,”total”:1}

On updating struts.xml as

 <result-types>
        <result-type name="json" class="org.apache.struts2.json.JSONResult" />
        </result-types>
        <action name="listUsers" class="com.oxxo.pilot.web.action.ListUsers">
            <result name="success" type="json">/jsp/userList.jsp</result>
            <result name="input" type="json">/jsp/userList.jsp</result>
        </action>

the json data is displayed on the browser.

Thanks,
Shikha

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:49:31+00:00Added an answer on May 28, 2026 at 10:49 pm

    The correct solution is :

    Struts.xml:

    <result-types>
                <result-type name="json" class="org.apache.struts2.json.JSONResult" />
            </result-types>
    
    <action name="listUsers" method="getAllApplicationData"   class="com.pilot.web.action.ListUsers">
                <result name="success">/jsp/userList.jsp</result>
                <result name="input">/jsp/fail.jsp</result>
            </action>
            <action name="getData" method="getAllApplicationData"   class="com.pilot.web.action.ListUsers">
                <result name="success" type="json"></result>
            </action>
    

    Index.jsp

    <s:form action="/searchAndUpdate/listUsers" method="post">
            <s:submit name="ListUsers" value="List All Users" align="right" />
        </s:form>
    

    userList.jsp

    <%@ page contentType="text/html; charset=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 XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
    <sj:head jqueryui="true" jquerytheme="redmond"/>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="Content-Style-Type" content="text/css" />
    </head>
    <body>
    <h3>Application Users</h3>
    <s:actionerror/>
    <s:actionmessage/>
    <s:url id="remoteurl" action="/searchAndUpdate/getData"/>
        <sjg:grid
            id="gridtable" 
            caption="Application Users" 
            href="%{remoteurl}" 
            pager="true" 
            gridModel="gridModel" 
            rowList="10,15,20" 
            rowNum="15" 
            rownumbers="true" 
            resizable="true" 
            viewrecords="true" 
            name="gridModel" 
        >
            <sjg:gridColumn name="id" index="id" title="Id" formatter="integer" sortable="false"/>
            <sjg:gridColumn name="userName" index="userName" title="User Name" sortable="true"/>
            <sjg:gridColumn name="fullName" index="fullName" title="Full Name" sortable="false"/>
            <sjg:gridColumn name="email" index="email" title="EMail" sortable="false"/>
        </sjg:grid>
    </body>
    </html>
    

    This is a working code. Working perfectly fine 🙂

    The issue was :
    The jsp accepts data type json as an input & the action ListUsers has to render a jsp. So, I made two different actions. One that returns “json” which serves as an input to the jsp & one which renders the jsp on success.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.