2012-01-13 57 views
0

我試圖按照「介紹Play框架」中的示例進行操作。我已經部署了工作至今這裏如何整理以下Play Framework路由?

http://vivid-beach-8523.herokuapp.com/

當我做例如iPad上搜索它的「亂」 URL出現

http://vivid-beach-8523.herokuapp.com/search?search=ipad&submit=Search

我認爲我正確地有路由設置(在conf /路由),因爲當我使用'乾淨'的網址時,它提出了正確的結果

http://vivid-beach-8523.herokuapp.com/search/IPad

我不確定如何讓我的表單顯示乾淨的URL。原始的HTML是

<div id="searchdiv"> 
    <form action="@{Application.search()}" method="GET"> 
     <input type="text" id="search" name="search" /> 
     <input type="submit" id="submit" name="submit" value="Search" /> 
    </form> 
</div> 

Application.search如下

public static void search(String search, Integer page) { 
    if (page == null) page = 1; 
    SearchResults results = AuctionItem.search(search, page); 
    render(results, page, search); 
} 

任何幫助的,我需要改變大加讚賞的東西。在需要的情況下,路線文件看起來像以下

GET  /listing/create   Application.createAuctionItem 
POST /listing/create   Application.doCreateItem 
GET  /listing/show/{id}    Application.show 
GET  /listing/show    Application.show 
GET  /search/{search}  Application.search 
GET  /search  Application.search 
GET /          Application.index 

回答

0

您不需要提交按鈕中的名稱。否則,它將作爲表單的參數發送。 只要把

<input type="submit" id="submit" value="Search" /> 

應該是好的,我猜。 而您需要將表單中的網址與您在路由中指定的網址相匹配。使用jQuery 一個可能的解決方案可能是這樣的:

<script type="text/javascript> 
$(document).ready(function(){ 
    $('#searchdiv form').submit(function(e){ 
    e.preventDefault(); 
    // not a good design though, once you change the route to Application.search, 
    // this will failed 
    this.attr('action', '/search/'+$('input#search').val()); 
    this.submit(); 
    }); 
}); 
</script> 
+0

順便說一句,()的Application.search參數的數量不匹配的形式。這可能是另一個問題 – dwi2 2012-01-13 06:43:18