anoop
anoop

Reputation: 1614

How to show pagination using display tag in struts2

I am using struts2 and hibernate and now i want to know how to use the display tag in struts2.

I have an action class CityList.java which is fetching all the cities from database.

Here is my action page CityList.java

package com.actions;

import com.opensymphony.xwork2.ActionSupport;
import com.zoondia.hbmObj.City;
import com.zoondia.Dao.CityDao;
import java.util.List;

public class CityList extends ActionSupport { 
    private List<City> cityList;
    public String getAllCities(){  
        cityList = CityDao.getInstance().getAllcity();
        return SUCCESS;
    }

    public List<City> getCityList() {
        return cityList;
    }

    public void setCityList(List<City> cityList) {
        this.cityList = cityList;
    }

}

All city i can list using the struts iterator tag but i need to show pagination using display tag.

My question is in the variable i got all the city details but how should shoe it as pagination.

I have tried it with

<display:table name="sessionScope.CityList.cityList" >

        </display:table>

in JSP page but it is not displaying any result. Instead it showing an error message. My question is i got all the city details in the variable "cityList" from the action page and all data i can display using an iterator tag. But how could i display this data inside an display tag.


Here is the error message

java.lang.NoClassDefFoundError: org/apache/commons/lang/UnhandledException

also for your information i am using Struts2

Upvotes: 0

Views: 1896

Answers (1)

Umesh Awasthi
Umesh Awasthi

Reputation: 23587

My first question is what error message its showing?? as error message in-itself is self explanatory sometime.

As per you inputs its not showing any results so please make sure you are getting data from your ORM layer and check its size and values in your action class for testing purpose. To use pagination in Display tag all you need to pass the pagesize attribute.When a pagesize is set, the displaytag library will break the list of objects into various pages. The page links will be added at the bottom.

<display:table list="cityList" pagesize="4" requestURI="cityListAction">
   // any display show logic goes here
</display:table>

In you case you are using sessionScope which require the list to be set using session like

<%
    session.setAttribute( "cityList", fetch list from action hee);
%>

Upvotes: 1

Related Questions