Playframework不显示Form标签:Scala

时间:2014-02-18 07:20:12

标签: html forms scala playframework-2.2

我正在尝试关注播放框架教程,该教程可以在' localhost:9000'中找到。

正如它所说,我编辑了文件并进行了编译,但它没有显示我预期的结果。 跟随就是我所做的。

  1. 在控制台中制作播放项目(命令:播放新的alpha)
  2. 然后我跑了(移动' alpha'目录和播放)
  3. 制作一个名为' models'的文件夹。 at / alpha / app / controllers。
  4. 编辑Application.scala

    package controllers
    
    import play.api._ 
    import play.api.mvc._ 
    import play.api.data._ 
    import play.api.data.Forms._
    
    import models.Task
    
    object Application extends Controller {
    
      val taskForm = Form("label" -> nonEmptyText)
    
      def index = Action {
        //Ok(views.html.index("Your new application is ready."))
        //Ok("Let's Play!")
        Redirect(routes.Application.tasks)   }
    
      def tasks = Action {
        Ok(views.html.index(Task.all(), taskForm))   }   def newTask = Action { implicit request =>
        taskForm.bindFromRequest.fold(
          errors => BadRequest(views.html.index(Task.all(), errors)),
          label => {
            Task.create(label)
            Redirect(routes.Application.tasks)
          }
        )   
      }   def deleteTask(id: Long) = TODO 
    }
    
  5. 制作/alpha/controllers/models/Task.scala

    package models
    
    case class Task(id: Long, label: String)
    
    object Task {   
      def all(): List[Task] = Nil   
      def create(label: String) {}   
      def delete(id: Long){} 
    }
    
  6. 最后我编辑了/ alpha / conf / routes

    # Routes
    # This file defines all application routes (Higher priority routes first)
    # ~~~~
    
    # Home page
    GET     /                           controllers.Application.index
    
    # Map static resources from the /public folder to the /assets URL path
    GET     /assets/*file               controllers.Assets.at(path="/public", file)
    
    #Tasks
    GET     /tasks                  controllers.Application.tasks
    POST    /tasks                  controllers.Application.newTask
    POST    /tasks/:id/delete       controllers.Application.deleteTask(id: Long)
    
  7. 然后我跑了。我期望一个表单区域和一个按钮“创建”#。按钮没问题,而Form没有。我收到了一些消息而不是表格。下面是那条消息。

      

    BaseScalaTemplate(play.api.templates.HtmlFormat$@6435477c)   (taskForm("标签&#34))

  8. 我无法追踪这一点,因为这不是错误。有没有任何线索来修复这个错误?如果你给出一个非常感激的解决方案或线索:D

    ==========感谢分享我的问题======================

    [index.scala.html]

    > @* Comment : @(message: String) *@ @(task: List[Task], taskForm:
    > Form[String]) @import helper._
    > 
    > @main("Todo list") {
    > 
    >   <h1>@task.size task(s)</h1>
    > 
    >   <ul>
    >     @task.map { task =>
    >       <li>
    >         @task.label
    > 
    >         @form(routes.Application.deleteTask(task.id)) {
    >           <input type="submit" value="Delete">
    >         }
    >       </li>
    >     }   </ul>
    > 
    >   <h2>Add a new task</h2>
    > 
    >   @form(routes.Application.newTask) {
    >     @inputText (taskForm("label"))
    >     <input type="submit" value="Create">   } }
    

1 个答案:

答案 0 :(得分:0)

我发现了错误。真的很失望:-( @inputText和参数之间有一个空格。

应该是:

@inputText (taskForm("label")) -- change to --> @inputText(taskForm("label"))

无论如何,谢谢你的帮助:D

相关问题