简体   繁体   中英

Play framework Controller Inheritance

I was trying to create a Controller inheritance to check how does Interceptions work.

The default controller ie 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.

您想要将welcome.html从views/Application移到views/App

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM