I have been trying to bind my android multiform data to the play framework form binding. But right now its seems to be complaining that the Date format binding failed. Any help would be really greatly appreciated!
The format I am currently sending over from the android app is "yyyy-MM-dd"
Things if have tried:
- Tried to set my own date format in the "application.conf" to date.format=yyyy-MM-dd
Tried to set the the java.util.Date format manually.
val format = new java.text.SimpleDateFormat("yyyy-MM-dd") format.format(new java.util.Date())
Here is Http data mapping i receive from Android retrofit. I did a println on the "request.body.dataParts"
Map(stock -> List(11), productname -> List(pleasework), price -> List(11.0), userid -> List(test), brand -> List(nike), condition -> List(New (with defects)), date -> List("2015-09-20"), category -> List(Shoe), ean -> List(e0ee9583-fb10-43c1-80f3-c1725251adfc), sold -> List(true))
Error message Play Framework is complaining:
Binding Failed
List(FormError(date,error.date,List()))
Play Framework Controller Code:
val format = new java.text.SimpleDateFormat("yyyy-MM-dd")
format.format(new java.util.Date())
val userForm = Form(
mapping(
"ean" -> text,
"date" -> of(dateFormat),
"sold" -> boolean,
"productname" -> text,
"userid" -> text,
"price" -> of(doubleFormat),
"stock" -> number,
"brand" -> text,
"category" -> text ,
"condition" -> text
)(Product.apply)(Product.unapply)
)
def multiuploaddata = Action(parse.multipartFormData) {
implicit request =>
userForm.bindFromRequest()(request).fold (
errFrm =>{
println("Binding Failed")
println(errFrm.errors)
},
userData => {
println("Success bind: " + userData.ean)
}
)
}
Ok("Receive MultiImage is okay!")
}
Android Retrofit Interface Code:
@Multipart
@POST("/multiuploaddata")
void updateProductImageData(@Part("ean") String ean,
@Part("date") Date date,
@Part("sold") boolean sold,
@Part("productname") String productname,
@Part("userid") String userid,
@Part("price") double price,
@Part("stock") int stock,
@Part("brand") String brand,
@Part("category") String category,
@Part("condition") String condition
, @PartMap Map<String, TypedFile> Files, Callback<Photo> callback);
Android Fragment onClickListener:
mDoneButton = (Button) v.findViewById(R.id.done_button);
mDoneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Calling the retrofit Interface to send Data and Images over to server
service.updateProductImageData(mProduct.getId().toString(),
mProduct.getDate(), mProduct.isSold(), mProduct.getProductName(),
mProduct.getUserId(), mProduct.getPrice(), mProduct.getStock(), mProduct.getBrand(), mProduct.getCategory()[0],
mProduct.getCondition()[0], files, new retrofit.Callback<Photo>() {
@Override
public void success(Photo photo, Response response) {
Log.d(TAG, "SUCCESS UPLOAD MULTI IMAGE!!! " + response);
}
@Override
public void failure(RetrofitError error) {
}
});