Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PaginationParams.java
package viewmodel;
import play.mvc.QueryStringBindable;
import java.util.Map;
import java.util.Optional;
public class PaginationParams implements QueryStringBindable<PaginationParams> {
private int page;
private int offset;
private int limit;
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public int getOffset() {
return offset;
}
public void setOffset(int offset) {
this.offset = offset;
}
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
@Override
public Optional<PaginationParams> bind(String key, Map<String, String[]> parameters) {
final String page = parameters.get("page")[0];
final String offset = parameters.get("offset")[0];
final String limit = parameters.get("limit")[0];
this.page = Integer.parseInt(page);
this.offset = Integer.parseInt(offset);
this.limit = Integer.parseInt(limit);
return Optional.of(this);
}
@Override
public String unbind(String key) {
return null;
}
@Override
public String javascriptUnbind() {
return null;
}
}
package controllers;
import play.mvc.Controller;
import play.mvc.Result;
import viewmodel.PaginationParams;
public class PaginationParamsTest extends Controller {
public Result test(PaginationParams paginationParams) {
final int limit = paginationParams.getLimit();
final int offset = paginationParams.getOffset();
final int page = paginationParams.getPage();
return ok("");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.