Reputation: 4829
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?
Upvotes: 1
Views: 11999
Reputation:
u dont need to do any thing just use list variable in display tag name i.e
<display:table name="yourListnameinaction">
</display>
Upvotes: 0
Reputation:
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>
Upvotes: 0
Reputation: 7851
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.
Upvotes: 0
Reputation: 1610
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;
}
Upvotes: 2
Reputation: 125
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}" ...
Upvotes: 0