2013-08-04 50 views
2

我試圖實現一個過濾器功能,它將按類型顯示業務。這是「搜索表單」,用戶可以選擇他們想顯示什麼類型的企業玩框架 - 簡單表達式的非法開始

@(businessList: List[Business], formSearch: Form[Business]) 

@import helper._ 

@main("All businesses"){ 

@form(action=routes.Application.displayAllBusinesses("")){ 
    @select(formSearch("type"),options(Seq("Dining","Accomodation","Manufacturing","Retail", "Services")),'_label ->"Business Type",'_default->"--Select a business type--") 

    <input type="submit" class="btn btn-success" value="Search by type"> 
    <a class="btn" href="@routes.Application.displayAllBusinesses()">Show all businesses</a> 
    <a class="btn" href="/registerBusiness">Register a business</a> 
} 

然後,我有一個循環來顯示所有的業務:

<ul> 
    @for(business <- businessList) { 
     <li> 
      <p>Business Name: @business.getName()</p> 
      <p>Business Type: @business.getType()</p> 
      <p>Business Email: @business.getEmail()</p> 
      <p>Business Location: @business.getLocation()</p> 
      <p>Business Description: @business.getDescription()</p> 
      <p>Id is: @business.id </p> 

      <a class="btn" href="@routes.Application.displayUpdateBusiness(business.id)">Update</a> 
      @form(routes.Application.deleteBusiness(business.id)) { 
       <input class="btn" type="submit" value="Delete"> 
      } 
     </li> 
    } 
</ul> 

當用戶提交其形式displayAllbusinesses路徑看起來像(這是其中錯誤出現):

GET  /listBusinesses   controllers.Application.displayAllBusinesses(type: String ?= "all") 

在應用該方法displayAllbusinesses/Application.java是:

public static Result displayAllBusinesses(String type){ 
    List<Business> businesses; 
    if(type=="all"){ 
     businesses = allBusinesses; 
    } else { 
     businesses = Business.find.where().like("type", type).findList(); 
     //TRACE 
     System.out.println(businesses); 
    } 
    return ok(listBusinesses.render(businesses, businessForm)); 
}    

當我運行此代碼時,我得到了/ listBusinesses路由的「非法啓動簡單表達式」。這是什麼意思?

+0

你說你有叫'displayAllBusinesses'的方法,但是你已經粘貼了方法'goToBusinessListPage',怎麼回事? – lpiepiora

+0

woops,我的壞。更正 –

回答

1

答:我在路線

controllers.Application.displayAllBusinesses(Type: String ?= "all") 

資本類型,改變了搜索表單有型資本也

@form(action=routes.Application.displayAllBusinesses("")){ 
@select(formSearch("Type"),options(Seq("Dining","Accomodation","Manufacturing","Retail", "Services")),'_label ->"Business Type",'_default->"--Select a business type--") 

它現在。去圖

+1

您應該將您的問題標記爲已解決。 –

3

類型是斯卡拉的保留關鍵字。路由編譯器沒有正確轉義它,我認爲這是一個已知的錯誤。

+0

與單詞「包」有相同的問題 – nemoo