2014-02-21 2 views
2

, Grid (Editable/Multiselect)에서 설명한대로 struts2-jquery-grid-3.7.0 플러그인을 사용하여 Struts jQuery 격자를 사용하려고합니다.struts2-jquery-grid 플러그인을 사용하여 Struts2의 격자

는 Struts는 형성 :

<s:form namespace="/admin_side" action="Test" validate="true" id="dataForm" name="dataForm"> 
    <s:url id="remoteurl" action="TestGrid" namespace="/admin_side"/> 
    <s:url id="editurl" action="edit-grid-entry"/> 
    <sjg:grid 
     id="gridmultitable" 
     caption="Example (Editable/Multiselect)" 
     dataType="json" 
     href="%{remoteurl}" 
     pager="true" 
     navigator="true" 
     navigatorSearchOptions="{sopt:['eq','ne','lt','gt']}" 
     navigatorAddOptions="{height:280, width:500, reloadAfterSubmit:true}" 
     navigatorEditOptions="{height:280, width:500, reloadAfterSubmit:false}" 
     navigatorEdit="true" 
     navigatorView="true" 
     navigatorViewOptions="{height:280, width:500}" 
     navigatorDelete="true" 
     navigatorDeleteOptions="{height:280, width:500,reloadAfterSubmit:true}" 
     gridModel="gridModel" 
     rowList="5,10,15" 
     rowNum="5" 
     rownumbers="true" 
     editurl="%{editurl}" 
     editinline="true" 
     multiselect="true" 
     onSelectRowTopics="rowselect" 
     > 

     <sjg:gridColumn name="countryId" index="countryId" title="Id" formatter="integer" editable="false" sortable="true" search="true" sorttype="integer" searchoptions="{sopt:['eq','ne','lt','gt']}"/> 
     <sjg:gridColumn name="countryName" index="countryName" title="Country Name" editable="true" edittype="text" sortable="true" search="true" sorttype="text"/> 
     <sjg:gridColumn name="countryCode" index="countryCode" title="Country Code" sortable="true" search="true" editable="true" sorttype="text"/> 

    </sjg:grid> 
</s:form> 

액션 클래스 :

following 스냅 샷과 같이 다음 및 이전 페이지 매김 링크가 항상 비활성화됩니다
@Namespace("/admin_side") 
@ResultPath("/WEB-INF/content") 
@ParentPackage(value = "json-default") 
@InterceptorRefs(@InterceptorRef(value = "store", params = {"operationMode", "AUTOMATIC"})) 
public final class TestAction extends ActionSupport implements Serializable 
{ 
    @Autowired 
    private final transient CountryService countryService=null; 
    private static final long serialVersionUID = 1L; 
    // Result List 
    private List<Country> gridModel; 
    // Get how many rows we want to have into the grid - rowNum attribute in the grid 
    private Integer rows=5; 
    // Get the requested page. By default grid sets this to 1. 
    private Integer page=1; 
    // 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; 
    // The 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; 
    // All Records 
    private Integer records; 

    @Action(value = "TestGrid", 
    results = { 
     @Result(name = ActionSupport.SUCCESS, type = "json", params = {"includeProperties", "gridModel\\[\\d+\\]\\.countryId, gridModel\\[\\d+\\]\\.countryName, gridModel\\[\\d+\\]\\.countryCode", "excludeNullProperties", "true"})}, 
    interceptorRefs = { 
     @InterceptorRef(value = "json")}) 
    public String execute() { 
     records=countryService.rowCount().intValue(); 
     total=new BigDecimal(records).divide(new BigDecimal(rows), 0, BigDecimal.ROUND_CEILING).intValue(); 
     gridModel=countryService.getList(page, rows, null, null); 

     System.out.println("records "+records+" total "+total+" Page " + getPage() + " Rows " + getRows() + " Sort Order " + getSord() + " Index Row :" + getSidx()+"Search :" + searchField + " " + searchOper + " " + searchString); 
     return SUCCESS; 
    } 

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

    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 getRecords() { 
     return records; 
    } 

    public void setRecords(Integer records) { 
     this.records = records;    
    } 

    public List<Country> getGridModel() { 
     return gridModel; 
    } 

    public void setGridModel(List<Country> 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) { 
     this.searchField = searchField; 
    } 

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

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

    @Action(value = "Test", 
    results = { 
     @Result(name = ActionSupport.SUCCESS, location = "Test.jsp"), 
     @Result(name = ActionSupport.INPUT, location = "Test.jsp")}, 
    interceptorRefs = { 
     @InterceptorRef(value = "defaultStack", params = {"validation.validateAnnotatedMethodOnly", "true", "validation.excludeMethods", "load"})}) 
    public String load() throws Exception { 
     return ActionSupport.SUCCESS; 
    } 
} 

.

enter image description here

일 때는, 페이지 1 1. 페이지가 더 이상 없습니다. 따라서 링크가 비활성화됩니다. execute() 방법에

그러나, records31total 5Rows 1- Page 7 초기화된다. 정렬, 검색, 편집, 행 추가를위한 링크/단추를 클릭했는지 여부에 관계없이 다른 모든 속성은 항상입니다.

여기에서 무엇을 간과하겠습니까?

답변

1

그리드가 제대로 작동하는 데 필요한 필드를 json 결과에 포함하는 것을 잊었습니다.

@Result(type = "json", params = {"includeProperties", "gridModel\\[\\d+\\]\\.countryId, gridModel\\[\\d+\\]\\.countryName, gridModel\\[\\d+\\]\\.countryCode, total, records, rows, page, sord, sidx, searchField, searchString, searchOper", "excludeNullProperties", "true"}) 

로 변경 또한, json 인터셉터는 필요하지 않지만 params가 필요합니다.

@InterceptorRef("params") 
+0

감사합니다. 이것은 효과가 있었다. 그 재산은 정말로'sord'가 아니라'sort'입니까? 'sort '로 이름을 붙이면 작동하지 않습니다. – Tiny