Pagination through Struts2 using DisplayTag Library Framework

后端 未结 5 1609
夕颜
夕颜 2021-01-16 18:13

I want to apply pagination for some class of my application, in which i am using spring, struts2 & hibernate. Here i am calling action class from welcome.jsp file. It ha

相关标签:
5条回答
  • 2021-01-16 18:44

    Use the following code.Instead of list attribute use name attribute.

    <display:table name="countryList" requestURI="CountryAllAction" pagesize="3">
     <display:column property="id" title="ID" />
     <display:column property="name" />
    </display:table>
    
    0 讨论(0)
  • 2021-01-16 18:45

    You need make "countryList" available to DisplayTag, e.g. by doing something like:

       request.setAttribute("countryList", countryList);
    

    in your action (unless there's a cleverer Struts2 way of doing this). I think you can get hold of the request in your action by making it implement ServletRequestAware

    You also need to make sure that your Country class has id and name properties.

    0 讨论(0)
  • 2021-01-16 19:05

    You need to have a getter for your countryList in your action.

    List<Country> countryList = new ArrayList<Country>();
    
    public String executeAction() throws Exception {
      try {
         countryList = this.countrySecurityProcessor.findByAll(0, null, null, null, null, false, false, null, null, null, null, 0);
         System.out.println("countryList = "+countryList);
         return ActionSupport.SUCCESS;
    
      } catch (Exception ex) {
         return ActionSupport.ERROR;
      }
    
    }
    
    public List<Country> getCountryList() {
      return countryList;
    }
    
    0 讨论(0)
  • 2021-01-16 19:06

    u dont need to do any thing just use list variable in display tag name i.e

    <display:table name="yourListnameinaction">
    
    </display>
    
    0 讨论(0)
  • 2021-01-16 19:08

    I'm not familiar with Struts2 but it seems that DisplayTag can't find your countryList in any scope.

    I don't see you putting countryList in from or request. If I'm not right may be you need to specify form name like <display:table list="${yourStrutsFormName.countryList}" ...

    0 讨论(0)
提交回复
热议问题