RESTful paging using EntityQuery in seam

Extending EntityQuery in seam 2.0.1 GA is not working properly. For some reason, the 'firstResult' is not injected by default and isNextExists() method always return false. The solution i found was to override both setFirstResult() and isNextExists() method. I manually injected the firstResult request context parameter, created an implementation of isNextExists() and everything seems to be working. Here is my EntityQuery subclass:

@Name("userList")
public class UserList extends EntityQuery {

private static final long serialVersionUID = 4676553441988735518L;

public UserList() {
setMaxResults(2);
}

@Override
public String getEjbql() {
return "select user from User user";
}

@RequestParameter("firstResult")
@Override
public void setFirstResult(Integer firstResult) {
if(firstResult==null) {
firstResult = 0;
}
super.setFirstResult(firstResult);
}

@Override
public boolean isNextExists() {
if(getFirstResult() + getMaxResults() < getResultCount()) {
return true;
}
return false;
}
}


And my xhtml code:


<s:link view="/userList.xhtml" value="Previous" rendered="#{userList.previousExists}">
<f:param value="#{userList.previousFirstResult}" name="firstResult" />
</s:link>

<s:link view="/userList.xhtml" value="Next" rendered="#{userList.nextExists}">
<f:param value="#{userList.nextFirstResult}" name="firstResult" />
</s:link>

3 comments:

Hi Rey,

Have you tried using

<page view-id="/userList.xhtml">
<param name="firstResult" value="#{userList.firstResult}" />
</page>

in pages.xml instead of overriding these methods?

October 6, 2008 at 3:45 AM  

hello tomas,

thanks for this. i'll give it a try if i get time to study seam again.

anyway please visit my main site www.reyjexter.com. i have interesting topics in there aswell.

thanks

sincerely,
rey

October 9, 2009 at 3:22 AM  

Thank you. You helped me a lot

May 15, 2014 at 2:33 PM  

Newer Post Older Post Home

Blogger Template by Blogcrowds