tags:

views:

4536

answers:

6

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'

Anyone have solution, then plz reply... Thankx in advance...

A: 

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}" ...

andrey
+2  A: 

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;
}
Ruggs
A: 

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.

A_M
A: 

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

A: 

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

A: 

This is great information about applying pagination on struts2 application...I would like to know what the method countrySecurityProcessor.findByAll() does and what paramter it takes in....Thank you.

Emzee
findByAll() method will take each field of my country table, and it will returns the filtered records depends on the parameters passed to this method, it will not apply any filter if we will pass null or 0 in the parameter list.
Nirmal