1
votes

I am self teaching myself Play framework and purchased "Play for Java" from Manning. I following their directions how since the book has been published there has been some updates (naturally). I am getting the following error:

Action not found For request 'GET /products'

package controllers;

import play.mvc.Controller;
import play.mvc.Result;

public class Products extends Controller {

  public static Result list(){
    return TODO;
  }

  public static Result newProduct(){
    return TODO;
  }

  public static Result details(String ean){
    return TODO;
  }

  public static Result save(){
    return TODO;
  }

}

GET / controllers.Application.index()

GET /assets/*file controllers.Assets.at(path="/public", file)

GET /products/ controllers.Products.list()

GET /products/new controllers.Products.newProduct()

GET /products/:ean controllers.Products.details(ean: String)

POST /products/ controllers.Products.save()

I used HTML tags for this, I hope that was correct way to post on here.

1

1 Answers

0
votes

The last time I used the Play Framework it was necessary to handle paths with trailing slashs separately, because the routing engine of this framework does.

So you either add the trailing slash to your URL, or you change to following line in your routes file:

GET /products/ controllers.Products.list()

to:

GET /products controllers.Products.list()

Workaround

I used the following code to remove trailing slashs from the URL:

Add this lines to your routes file:

# Reroute URL with a trailing slash
GET    /*path/    controllers.Reroute.trailingSlash(path: String)

This is the corresponding class:

public class Reroute extends Controller {
    public static Result trailingSlash(String path) {
        /**
         * Moved_Permantly is an HTTP code that indicates a moved ressource. The browser will
         * cache the new address and redirect automatically if the user enters the old URL again.
         */
        return movedPermanently("/" + path);
    }
}

If I remember correctly contains the path variable the path without a trailing slash. If you use this code, please check that every route is specified without a trailing slash or that route won't work anymore.