播放2.2斯卡拉视图的一对多关系

时间:2014-01-14 23:04:04

标签: java scala playframework

我试图在提交操作中同时保存Play框架中的一对多关系。意味着将客户和地址保存在一起。

这种关系是许多地址的一个客户。

在View中,我希望Address scala可重用,所以我在下面声明了addressTemplate.scala.html。

    @(addressField: Field)(title: String)
        <h5>@title</h5>

            @inputText(
                addressField("address1"), 
                '_label -> "Address1"
            )     
    ....

    Now, my Parent scala view customer.scala.html is like below. it creates blank form on GET customer action.

    @(customerForm: Form[Customer])        
      @form(routes.CustomerContoller.submit()) {                
                @inputText(
                    partnerForm("firstname"), 
                    '_label -> "First name"
                )
                ....                
          @for(address <- customerForm("addresses")) {
                 @addressTemplate(address)("Billing Address")
          }                     

I know, the for loop just above is not correct, and not compiling, that's where I need experts help.
Question is: how to design the view to support Customer multiple Addresses. The AddressTemplate takes Field as parameter, I need get the address/addressForm and pass, not sure how to get the ChildForm. Hope the question is clear, if not please let me know. 

Models
======
Btw, the Model relationship are like below.

public class Customer extends BaseModel {
    ...
    @OneToMany(cascade = CascadeType.PERSIST)
    public List<Address> addresses;

0 个答案:

没有答案