Java – Pagination through Struts2 using DisplayTag Library Framework

javastruts2

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 has following code :

<s:form action="marketing/allCountry.action">  
         <s:submit value="Click"></s:submit>  
         </s:form>  

Now my allCountry.action class of java has following code :

public String executeAction() throws Exception {
        try {
            countryList = new ArrayList<Country>();
            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;
        }
}

It fetches the data properly, that i confirmed by printing countryList object. But now i am redirecting from SUCCESS to country.jsp. The code of country.jsp is :

<display:table list="countryList" requestURI="CountryAllAction" pagesize="3">
    <display:column property="id" title="ID" />
    <display:column property="name" />
</display:table>

Now at the time executing my application i am getting run time error like :

javax.servlet.ServletException: javax.servlet.ServletException:
Exception: [.LookupUtil] Error looking up property "id" in object type
"java.lang.String". Cause: Unknown property 'id'

What is the solution to this type of error?

Best Solution

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;
}
Related Question