2013-09-26 19 views
0
# Routes 
# This file defines all application routes (Higher priority routes first) 
# ~~~~ 

# Home page 
GET /     controllers.Application.index() 

# Tasks 
GET  /tasks    controllers.Application.tasks() 
POST /tasks    controllers.Application.newTask() 
POST /tasks/:id/delete controllers.Application.deleteTask(id: Long) 

# Map static resources from the /public folder to the /assets URL path 
GET  /assets/*file  controllers.Assets.at(path="/public", file) 

的網址:PlayFramework 2.1.5 /的Java /動作

http://localhost:9000/tasks/2/delete 

錯誤:

Action not found 

For request 'GET /tasks/2/delete' 
These routes have been tried, in this order: 

1 GET /      controllers.Application.index() 
2 GET /tasks      controllers.Application.tasks() 
3 POST /tasks      controllers.Application.newTask() 
4 POST /tasks/$id<[^/]+>/delete controllers.Application.deleteTask(id:Long) 
5 GET /assets/$file<.+>   controllers.Assets.at(path:String = "/public", file:String) 

的HTML片段:

<form action="/tasks/2/delete" method="POST" > 
    <input type="submit" value="Delete"> 
</form> 

我不不明白爲什麼規則#4不適用。

我的錯誤在哪裏?

回答

0

我終於完成自己的POST請求添加缺少ID:

@(tasks: List[Task], taskForm: Form[Task]) 

@import helper._ 

@main("Todo list") { 
    <h1>@tasks.size() task(s)</h1> 
    <ul> 
    @for(task <- tasks) { 
     <li> 
     @task.label 
     @form(routes.Application.deleteTask(task.id)) { 
      <input type="hidden" id="id" value="@task.id"><!-- *** added ***--> 
      <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"> 
    } 
} 

生成的HTML是:PlayFramework 2.2.0

<form action="/tasks/1/delete" method="POST" > 
    <input type="hidden" id="id" value="1"> 
    <input type="submit" value="Delete"> 
</form> 

的todolist的樣品上的PlayFramework 2.1之上執行。 5不能很好地工作...

0

它說,它無法找到GET /tasks/2/delete因爲你只定義使用POST路線:

POST /tasks/:id/delete controllers.Application.deleteTask(id: Long) 

所以,你必須做一個POST請求,而不是GET。

+0

HTML添加到我以前的帖子,以顯示它是一個POST請求,我怎樣才能改變參數傳輸的方式? – Aubin

+1

@Aubin表單看起來不錯,應該儘可能地發送POST。也許一些JavaScript干擾表單提交?嘗試在瀏覽器網絡控制檯中查看實際發送的內容。 – Kapep