2
votes

I am trying to implement a filter functionality that will display businesses by their type. This is the "search form" where the user can select what type of business they want to display

@(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>
}

Then I have a for loop to display all the businesses:

<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>

When the user submits their form the displayAllbusinesses route looks like (This is where the error comes up):

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

The displayAllbusinesses method in app/Application.java is:

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));
}            

When I run this code I get a "illegal start of simple expression" for the /listBusinesses route. What does this mean?

2
You say you have method called displayAllBusinesses but you've pasted method goToBusinessListPage, how come? - lpiepiora
woops, my bad. correction - Connor Leech

2 Answers

3
votes

type is a reserved keyword in Scala. The route compiler is not escaping it properly, I think it's a known bug.

1
votes

Answer: I capitalized type in routes

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

and changed the search form to have type capitalized also

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

It works now. Go figure