I am using Play 1.2.5
I have a User model as below:
@Entity
public class User extends Model {
public String name;
public String city;
public String country;
public Integer zip;
}
The registration.html file is like this:
#{extends 'main.html' /}
#{set title:'Home' /}
<form action="@{Application.registerUser()}" method="get">
Name: <input type="text" name="txtName"><br>
City: <input type="text" name="txtCity"><br>
Country: <input type="text" name="txtCountry"><br>
Zip: <input type="text" name="txtZip"><br>
<input type="submit" value="Submit">
</form>
Below is the registerUser method in Application Controller:
public static void registerUser(String txtName,String txtCity,String txtCountry,Integer txtZip){
//some business logic
render();
}
The above signature works fine but I have to add a lot of parameters in the method which I dont want.
In a form, I have more than 15 fields, in such a case 15 parameters are too much!!!
Hence I need to know how to bind the user input values to a model (e.g. user model shown above) and pass it to the controller as an user object parameter to the method or as a map with key and value pairs (which ever is easier)?
Please let me know about this.
Regards,
Rename your input fields to
user.name,user.city, etc., and change the controller method toThis is described in the documentation.