java - Objects as input of a form in Play framework -


all examples of models , forms of play framework (i use 2.0.4) use string, int or long attributes.

however have model this:

public class mymodel {      @required     public string name;      @required     public date birthdate;      @required     public myclass someobject;     } 

now name can use @inputtext(...) field in form.

for birthdate tried using @inputdate(...) field in form, gives me input field , whatever format of date try enter in input field, gets rejected. tried passing 'format -> "dd/mm/yyyy" field, without success.

i don't know how can possibly enter myclass object form.

  1. how can make @inputdate() work?
  2. is necessary make every input string/int/long , upon receiving values in controller construct myclass object of them?

answer question number (1).

you may consider technique. model might below:

@required @formats.datetime(pattern="dd/mm/yyyy") public date birthdate; 

so, can make view simple as:

@helper.inputdate(myform("birthdate"), '_label -> "birthdate", '_help -> "format dd/mm/yyy") 

answer question number (2).

as far know, must have submitted value html form in form of string, int, long. because common format display information on screen. additionally, html input value represented in string, 'int', 'long' type.


fyi, there useful sample computer-database can learn model connected other class. located @ <playframeworkinstalldirectory>/samples/java/computer-database.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -