gigaZhang / struts2-jquery

Automatically exported from code.google.com/p/struts2-jquery
0 stars 0 forks source link

use /struts-jquery-grid-tags no data return #1124

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
(This is for feature requests and bugs in Struts2 jQuery Plugin - for
getting help, please use the User Group.
http://groups.google.com/group/struts2-jquery )

What steps will reproduce the problem?
1.JSP
<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<%@ 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 jqueryui="true" jquerytheme="black-tie" />
<s:set name="gridModel" value="gridModel" />
<title>Insert title here</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="js/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript">
    function search() {

        $("#gridtable").jqGrid('setGridParam').trigger("reloadGrid");
        alert('${gridModel}');

    }
</script>
</head>

<body onload="search();">
    <div style="position: relative;">
        <s:url id="urlUserProfileGrid" action="userProfileGrid" />
        <sjg:grid id="gridtable" caption="User Profile List" dataType="json"
            href="%{urlUserProfileGrid}" pager="true" gridModel="gridModel"
            rowList="15, 25, 50" rowNum="15" rownumbers="false" navigator="false"
            autowidth="true" navigatorRefresh="true" reloadTopics="reloadItems"
            onSelectRowTopics="rowselect">
            <sjg:gridColumn name="userId" index="userId" title="User ID1"
                sortable="true" width="30" align="center" />
            <sjg:gridColumn name="groupId" index="groupId" title="User Name"
                sortable="true" width="40" />

        </sjg:grid>
    </div>
</body>
</html>
2.Java
package com.hsbc.sgh.ibg.action.accesscontrol;

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

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.hsbc.sgh.ibg.action.common.GridActionSupport;
import com.hsbc.sgh.ibg.dao.model.Users;
import com.hsbc.sgh.ibg.service.accesscontrol.UserProfileService;
import com.hsbc.sgh.ibg.service.common.bean.Users_I;

@ParentPackage(value = "ibg")
public class UserProfileAction extends GridActionSupport {

    private static final long serialVersionUID = 3856432881874822389L;

    private Map<String, String> statusMap = new HashMap<String, String>();

    public UserProfileAction() {
        statusMap.put("A", "Active");
        statusMap.put("D", "Deactive");
    }

    private List<Users> usersList;

    private UserProfileService userProfileService;

    @Action(value = "/userProfileAction", results = { @Result(location = "accesscontrol/userProfile.jsp", name = SUCCESS) })
    public String execute() {
        return SUCCESS;
    }
    @Actions( { @Action(value = "/userProfileGrid", results = { @Result(name = SUCCESS, type = "json") }) })
    public String reloadGrid() {
        //usersList = userProfileService.getUsersList("", "");

        List<Users_I> l1=new ArrayList<Users_I>();

            Users_I users_I=new Users_I();
            users_I.setGroupId("99");
            l1.add(users_I);

        setRecords(usersList.size());

        setGridModel(l1);

        return SUCCESS;
    }

    public String getJSON() {
        return execute();
    }

    public UserProfileService getUserProfileService() {
        return userProfileService;
    }

    public void setUserProfileService(UserProfileService userProfileService) {
        this.userProfileService = userProfileService;
    }

    @Override
    public List<?> getGridModel() {
        return (List<?>) super.getGridModel();
    }

    @Override
    public Integer getPage() {
        return super.getPage();
    }

    @Override
    public Integer getRecords() {
        return super.getRecords();
    }

    @Override
    public Integer getRows() {
        return super.getRows();
    }

    @Override
    public Integer getTotal() {
        return super.getTotal();
    }

    @Override
    public Integer getTotalrows() {
        return super.getTotalrows();
    }

    /**
     * @return the statusMap
     */
    public Map<String, String> getStatusMap() {
        return statusMap;
    }

}

GridActionSupport.java

package com.hsbc.sgh.ibg.action.common;

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

import org.apache.commons.beanutils.BeanComparator;
import org.apache.commons.collections.comparators.ReverseComparator;
import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionSupport;

public class GridActionSupport extends ActionSupport implements SessionAware {
    private static final long serialVersionUID = 5078264277068533593L;

    // Sorting order constants
    protected static final String ASC = "asc";
    protected static final String DESC = "desc";

    // Search operation constants
    protected static final String EQ = "eq";
    protected static final String NE = "ne";
    protected static final String LT = "lt";
    protected static final String LE = "le";
    protected static final String GT = "gt";
    protected static final String GE = "ge";
    protected static final String BW = "bw";
    protected static final String BN = "bn";
    protected static final String IN = "in";
    protected static final String NI = "ni";
    protected static final String EW = "ew";
    protected static final String EN = "en";
    protected static final String CN = "cn";
    protected static final String NC = "nc";

    // Your result List
    private List<?> 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;

    // get index row - i.e. user click to sort.
    private String sidx;

    // Search Field
    private String searchField;

    // The Search String
    private String searchString;

    // Limit the result when using local data, value form attribute rowTotal
    private Integer totalrows;

    // 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;

    // All Records
    private Integer records = 0;

    private boolean loadonce = false;
    private Map<String, Object> session;
    private String beansId = getClass().getName() + "_actionbeans";

    @Override
    public String execute() {
        return SUCCESS;
    }

    public String getJSON() {
        return "";
    }

    /**
     * @return how many rows we want to have into the grid
     */
    public Integer getRows() {
        return rows;
    }

    /**
     * @param rows
     *            how many rows we want to have into the grid
     */
    public void setRows(Integer rows) {
        this.rows = rows;
    }

    /**
     * @return current page of the query
     */
    public Integer getPage() {
        return page;
    }

    /**
     * @param page
     *            current page of the query
     */
    public void setPage(Integer page) {
        this.page = page;
    }

    /**
     * @return total pages for the query
     */
    public Integer getTotal() {
        return total;
    }

    /**
     * @param total
     *            total pages for the query
     */
    public void setTotal(Integer total) {
        this.total = total;
    }

    /**
     * @return total number of records for the query. e.g. select count(*) from
     *         table
     */
    public Integer getRecords() {
        return records;
    }

    /**
     * @param record
     *            total number of records for the query. e.g. select count(*)
     *            from table
     */
    public void setRecords(Integer record) {
        this.records = record;
        if (this.records > 0 && this.rows > 0)
            total = (int) Math.ceil((double) this.records / (double) this.rows);
    }

    /**
     * @return an collection that contains the actual data
     */
    public List<?> getGridModel() {
        return gridModel;
    }

    /**
     * @param gridModel
     *            an collection that contains the actual data
     */
    public void setGridModel(List<?> gridModel) {
        this.gridModel = gridModel;
    }

    /**
     * @return sorting order
     */
    public String getSord() {
        return sord;
    }

    /**
     * @param sord
     *            sorting order
     */
    public void setSord(String sord) {
        this.sord = sord;
    }

    /**
     * @return get index row - i.e. user click to sort.
     */
    public String getSidx() {
        return sidx;
    }

    /**
     * @param sidx
     *            get index row - i.e. user click to sort.
     */
    public void setSidx(String sidx) {
        this.sidx = "".equals(sidx) ? null : sidx;
    }

    public void setSearchField(String searchField) {
        this.searchField = searchField;
    }

    public void setSearchString(String searchString) {
        this.searchString = searchString;
    }

    public void setSearchOper(String searchOper) {
        this.searchOper = searchOper;
    }

    public void setLoadonce(boolean loadonce) {
        this.loadonce = loadonce;
    }

    public void setTotalrows(Integer totalrows) {
        this.totalrows = totalrows;
    }

    @Override
    public void setSession(Map<String, Object> session) {
        this.session = session;
    }

    /**
     * @return the searchField
     */
    public String getSearchField() {
        return searchField;
    }

    /**
     * @return the searchString
     */
    public String getSearchString() {
        return searchString;
    }

    /**
     * @return the searchOper
     */
    public String getSearchOper() {
        return searchOper;
    }

    /**
     * @return the loadonce
     */
    public boolean isLoadonce() {
        return loadonce;
    }

    /**
     * @return the totalrows
     */
    public Integer getTotalrows() {
        return totalrows;
    }

    /**
     * @return the session
     */
    public Map<String, Object> getSession() {
        return session;
    }

    public void putBeans(List<?> beans) {
        session.put(beansId, beans);
    }

    public void putBeans(String id, List<?> beans) {
        session.put(id, beans);
    }

    public Integer getRowTo() {
        return Math.min(rows * page, records);
    }

    public Integer getRowFrom() {
        int from = (page - 1) * rows;
        if(getRowTo()< from) {
            page = 1;
            return 0;
        }
        return from;
    }

    public List<?> getBeans() {
        return (List<?>) session.get(beansId);
    }

    public List<?> getBeans(String id) {
        return (List<?>) session.get(id);
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public void doSortBeans(List<?> list) {
        /**
         * Sort beans
         */
        if(ASC.equals(getSord())&&getSidx()!=null)
            Collections.sort(list, new BeanComparator(getSidx()));
        else if(DESC.equals(getSord())&&getSidx()!=null)
            Collections.sort(list, new BeanComparator(getSidx(),new ReverseComparator()));
    }
}

3.

What is the expected output? What do you see instead?
Refer the JPG

Which struts2 version?
2.3.16.1

Which struts2-jquery plugin version?
3.7.0

Please provide any additional information below.

Original issue reported on code.google.com by yon17308...@gmail.com on 11 Dec 2014 at 7:32

Attachments: