开发者

how to create an html form for a model in playframework

开发者 https://www.devze.com 2023-04-05 14:03 出处:网络
In my application ,I have to present the user with an address input form.I have an Address model as given below.Do I need to create an html page from scratch to capture the user input,Or can I generat

In my application ,I have to present the user with an address input form.I have an Address model as given below.Do I need to create an html page from scratch to capture the user input,Or can I generate a form similar to the crud page in admin area?Which is the correct way to do this in playframework?

public class Address ex开发者_运维问答tends Model {    
    @Required
    String addressLine1;

    String addressLine2;

    String city;

    String state;

    String pincode;

    String phoneNumber;

    String country;
...
}


You can reuse the CRUD tags without the CRUD controllers!

#{crud.form class:'models.ModelName' /} 
#{curd.form object:anyInstance /} 

Please see my answer Advanced customization of CRUD forms and controllers in Play for more details.

PS.

This question was already asked but the accepted question was not satisfying for me, and I wanted to make it into a more generic question. So I asked it again but, still not getting any answer!, I finally found the solution myself :)


Using CRUD module to capture user input is easier and quicker way. CRUD Module exists for such cases. Regarding whether this is the correct way, it depends. It you have lot of customization then you can overide the crud templates and it should work.

Just create a Addresses Controller extending CRUD. It would be available as part of /admin/. Thats it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号