I am trying to follow play framework tutorial, which can see in 'localhost:9000'.
As it says, I Edited file and compile but it does not show the result that I expected. Follow is what I have done.
Edit 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
}
make /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){}
}
finally I edited /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)
then I ran. I expected a form area and a button 'create'. Button is fine while Form does not. I got some messages instead of the form. below is that message.
BaseScalaTemplate(play.api.templates.HtmlFormat$@6435477c) (taskForm("label"))
I can not track this, because it was not an error. Is there any clue to fix this bugs? If you give a solution or clue that would be very appreciated :D
========== Thanks for share my problem ======================
[ 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"> } }
I found the error. It is really disappointed:-( There is an white space between @inputText and parameters.
It should be :
@inputText (taskForm("label")) -- change to --> @inputText(taskForm("label"))
Anyway, thanks for help :D