Created
June 27, 2017 14:51
-
-
Save palmerabollo/e65b2859ba0301f06511d36edbb7c42d to your computer and use it in GitHub Desktop.
Play 2.5 QueryStringBindable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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