Skip to content

Instantly share code, notes, and snippets.

@asvignesh
Created April 10, 2018 15:04
Show Gist options
  • Save asvignesh/911ff1b6dd4b96a5368e9d113a6591d0 to your computer and use it in GitHub Desktop.
Save asvignesh/911ff1b6dd4b96a5368e9d113a6591d0 to your computer and use it in GitHub Desktop.
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