Skip to content

Instantly share code, notes, and snippets.

@palmerabollo
Created June 27, 2017 14:51
Show Gist options
  • Save palmerabollo/e65b2859ba0301f06511d36edbb7c42d to your computer and use it in GitHub Desktop.
Save palmerabollo/e65b2859ba0301f06511d36edbb7c42d to your computer and use it in GitHub Desktop.
Play 2.5 QueryStringBindable
package controllers.binders;
import org.joda.time.DateTime;
import org.joda.time.format.ISODateTimeFormat;
import play.mvc.QueryStringBindable;
import java.util.Date;
import java.util.Map;
import java.util.Optional;
public class DateParameter implements QueryStringBindable<DateParameter> {
private Date value;
@Override
public Optional<DateParameter> bind(String key, Map<String, String[]> params) {
if (params.containsKey(key)) {
String date = params.get(key)[0];
value = new DateTime(date).toDate();
return Optional.<DateParameter>of(this);
}
return Optional.<DateParameter>empty();
}
public Date getValue() {
return value;
}
@Override
public String javascriptUnbind() {
return null;
}
@Override
public String unbind(String key) {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment