user3673985
user3673985

Reputation: 67

illegal start of simple pattern - play framework

I am newbie to play framework. While trying to generate html template with play, I get the error illegal start of simple pattern at the line ticket.getTicketIds. Have been spending sometime trying to resolve the issue but of no good.

<tbody>
    @for( ticket <- @obj.getPurchasedTickets() ) {
      @for( (key,val) <- @obj.getTicketsCalculation() ) {
       @if( key.equals(ticket.getTicketId())) {
          <tr>
            <td class="desc">@ticket.getTicketName()<br></br>
            @if(ticket.getTicketIds() != null && !ticket.getTicketIds().isEmpty()) {
                @for( ticketid <- ticket.getTicketIds ){
                    #@ticketid 
                }
            }
            </td>
            <td class="unit">@ticket.getPrice()</td>
          </tr>
          }
       }
     }
 </tbody>  

The following POJOs are used to get the necessary values

public class PurchasedTicket {

  private String ticketId; // represents the ticket's id
  private String ticketName;
  private Integer numberOfTickets;
  private Double price;  
  private List<String> ticketIds; // list of tickets bought with this ticket

  // setters and getters

}

 public class Wrapper{

   private Map ticketsCalculation;
   private List<PurchasedTicket> purchasedTickets;

  // setters and getters
}

The obj represented in the template part is an object of Wrapper class

Upvotes: 2

Views: 634

Answers (2)

Rumid
Rumid

Reputation: 1709

Just to make it compile:

  1. As @rouge-one mentioned, you can use different variable name, eg. value.

  2. You shouldn't use multiple @ signs. As docs says, it should be used at the beginning of a dynamic statement, eg. @for( ticket <- obj.getPurchasedTickets() ) {

    so the working code should look like this:

    <tbody>
        @for(ticket <- obj.getPurchasedTickets()) {
            @for((key, value) <- obj.getTicketsCalculation()) {
                @if(key.equals(ticket.getTicketId())) {
                    <tr>
                        <td class="desc">@ticket.getTicketName()<br></br>
                            @if(ticket.getTicketIds() != null && !ticket.getTicketIds().isEmpty()) {
                                @for(ticketid <- ticket.getTicketIds){
                                    #@ticketid
                                }
                            }
                        </td>
                        <td class="unit">@ticket.getPrice()</td>
                    </tr>
                }
            }
        }
    </tbody>
    

Upvotes: 1

rogue-one
rogue-one

Reputation: 11587

change the attribute name from val to value in line 3 of your template since val is a reserved word.

 (key,value) <- @obj.getTicketsCalculation()

for example see below

scala> val (key, value) =  "key1" -> "val1"
key: String = key1
value: String = val1

scala> val (key, value) = "key1" -> "val1" key: String = key1 value: String = val1

scala> val (key, val) =  "key1" -> "val1"
<console>:1: error: illegal start of simple pattern
val (key, val) =  "key1" -> "val1"
          ^

Upvotes: 0

Related Questions