我試圖實現一個過濾器功能,它將按類型顯示業務。這是「搜索表單」,用戶可以選擇他們想顯示什麼類型的企業玩框架 - 簡單表達式的非法開始
@(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路由的「非法啓動簡單表達式」。這是什麼意思?
你說你有叫'displayAllBusinesses'的方法,但是你已經粘貼了方法'goToBusinessListPage',怎麼回事? – lpiepiora
woops,我的壞。更正 –