没有足够的方法适用于方法:播放框架,但我需要将参数传递给方法

时间:2018-06-05 12:21:22

标签: forms scala playframework play-templates

这里的问题是我想创建一个包含表单的模态。所以我创建了一个游戏template,我无法将表单从我的控制器传递到该模板或我称之为视图或模板的主视图中:为什么我无法将其传递到主视图中? - >我已经这样做了,我收到了not enough arguments for method apply当然我知道如果一个接收隐含为参数的方法被一个参数调用,scala会要求剩下的参数;在这种情况下,所有这些:@(customerform: Form[Customer],customers: Seq[Customer])(implicit flash:Flash, request: RequestHeader, messagesProvider: MessagesProvider)在视图顶部隐式存在,也必须传递给它。通过这个我甚至无法将Form[Customer]类型的参数传递给此Action方法:

def addCustomer() = Action { implicit request =>
    customerForm.bindFromRequest.fold(
      errorForm => {
        Redirect(routes.AdminController.customers())
          .flashing("error" -> "the form fields are not accurate")
      },
      customerForm => {

        val newCustomer =
          new Customer(customerForm.accountNumber, customerForm.customerId, customerForm.name)
        //val customerJson = newCustomer.as[Customer]
        Redirect(routes.AdminController.customers())
          .flashing("success" -> " customer added succesfully")

      }
    )
  }

  def show() = Action { implicit request =>
    val sForm = customerForm
    Ok(views.html.admin.customers)
  }

现在最烦人的问题是,如果我从show()Action方法中删除了参数,我就无法将表单传递给主视图。 那么,现在的问题是如何将Form[Contact]传递给模板或主视图,这样我就可以成功使用它而不需要编译器说not enough arguments或者我是否有办法通过所有这些参数(我个人认为这是不可行的)。

这是主要观点

@(customerform: Form[Customer],customers: Seq[Customer])(implicit flash:Flash, request: RequestHeader, messagesProvider: MessagesProvider)

@import helper._

@main("Customers", "settings") {

    <div class="row">
        <div class="col-xs-12">
            <div class="white-box">
                <div class="button-panel">

                </div>
                <div class="table-responsive">
                    <table class="table">
                        <thead>
                            <tr>
                                <th>Account Number</th>
                                <th>Customer ID</th>
                                <th>Customer Name</th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>
                            @for(customer <- customers ){
                            <tr>
                                <td>@customer.accountNumber</a></td>
                                <td>@customer.customerId</td>
                                <td>@customer.name</td>
                                <td></td>
                            </tr>
                            }
                        </tbody>
                    </table>
                </div>
                <!--please let me put my form here-->
                <div class="container">
                    <button class="btn-success" type="button" data-toggle="modal" data-target="formModal">add Customer</button>
                    @formModal(customerform)
                </div>
                <!-- pager goes here. -->
            </div>
        </div>
    </div>
}

这是模板:

@(form: Form[Customer])(implicit request: RequestHeader,messages: MessagesProvider)



import helper._

    <div class="modal-fade" id="formModal" >
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h2> Add Customer</h2>
                </div>
                <div class="modal-body">
                    @helper.form(action = routes.CustomerController.addCustomer()){
                    <fieldset>
                        <legend>
                            "Customer Details"
                        </legend>
                        @helper.inputText(form("Account Number"))
                        @helper.inputText(form("ID"))
                        @helper.inputText(form("Name"))
                    </fieldset>
                    <p><button><input type="submit" class="btn primary" value="Submit"></button></p>
                    }
                </div>
                <div class="modal-footer">
                    footer
                </div>

            </div>

        </div>

    </div>

请,任何帮助将不胜感激....

0 个答案:

没有答案