Reputation: 819
I was trying to create a Controller inheritance to check how does Interceptions
work.
The default controller i.e. Application.java
is like this:
@Before
static void display(){
System.out.println("Interception method \"Before\" invoked!!!");
}
public static void index() {
System.out.println("Inside index!!!");
render();
}
I created a new controller named App.java
and it is like this:
@With(Application.class)
public class App extends Controller {
public static void welcome(String txtName){
render(txtName);
}
}
Here is the index.html file:
#{extends 'main.html' /}
#{set title:'Home' /}
<form action="@{App.welcome()}" method="get">
Enter your name: <input type="text" name="txtName">
<input type="submit" value="Submit">
</form>
This is Welcome.html
file:
#{extends 'main.html' /}
#{set title:'Home' /}
Welcome ${txtName?:'Guest'}
I added this entry in routes file:
GET /InterceptionDemo controllers.App.welcome
When I enter the name and click the button in index.html
then I am getting an error:
The template App/welcome.html does not exist.
I am trying to use the App.java
controller but it is not working. The welcome.html
file is present under the views/Application
folder where the index.html
is also present.
Please let me know how to make it work...this is just a junk app trying it out for getting started with Play framework inheritance.
Thanks.
Upvotes: 2
Views: 591
Reputation: 10346
Tried your example, and it worked just fine. Placed the Welcome.html file in the wrong directory, and got the same error as you. But then created the views/App directory and placed it there, and it worked.
Upvotes: 2