Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hello World page does not work #9942

Closed
ranmx opened this issue Dec 24, 2019 · 5 comments
Closed

Hello World page does not work #9942

ranmx opened this issue Dec 24, 2019 · 5 comments

Comments

@ranmx
Copy link

ranmx commented Dec 24, 2019

Play Version

2.8.x

API

nop

Operating System

linux

JDK

java version "12.0.1" 2019-04-16
Java(TM) SE Runtime Environment (build 12.0.1+12)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)

Library Dependencies

nop

Expected Behavior

  1. copy and paste examples in https://www.playframework.com/documentation/2.8.x/ImplementingHelloWorld should work

Actual Behavior

comes out the error:

Compilation error
not enough arguments for method apply: (title: String, assetsFinder: controllers.AssetsFinder)(content: play.twirl.api.Html)play.twirl.api.HtmlFormat.Appendable in object main.
Unspecified value parameter assetsFinder.

In /users/a/play-samples-play-scala-starter-example/app/views/hello.scala.html:1
1@main("hello") { 
2    <section id="top">
3        <div class="wrapper">
4            <h1>Hello</h1>
5        </div>
@ranmx
Copy link
Author

ranmx commented Dec 24, 2019

it's due to the fact that the examples in play-samples-play-scala-starter-example are different from that of in playframework

@ignasi35
Copy link
Member

ignasi35 commented Jan 9, 2020

You're right. The tutorial is incorrect since main requires an assetsFinder paramter since playframework/play-samples@dc2b3fe

@ignasi35
Copy link
Member

ignasi35 commented Jan 9, 2020

The tutorial is incorrect for scala only. The problem is there's a single tutorial for both java and scala and the sample code the tutorial is based on differs in each implementation.

The commit playframework/play-samples@dc2b3fe moved the play-scala-starter-example to config-based Assets (and use of AssetsFinder) but the play-java-starter-example remained the same. This means the snippets in the tutorial are only valid for the Java users.

We have two options:

  1. move play-scala-starter-example back (undo playframework/play-samples@dc2b3fe)
  2. upgrade play-java-starter-example to config-based assets management.

The problem with option 1. is that it uses deprecated API (that was the motivation for the change in the commit linked in 1.)

The problem with option 2. is that the resulting code is a bit too verbose for a tutorial because assetsFinder has to be injected and passed everywhere. The impact of injecting and using assetsFinder is small in the scala implementations thanks to the use of implicits but in the java code it's very noisy in my opinion:

public class HomeController extends Controller {

    private final AssetsFinder assetsFinder;

    @Inject
    public HomeController(AssetsFinder assetsFinder) {
        this.assetsFinder = assetsFinder;
    }

    /**
     * An action that renders an HTML page with a welcome message.
     * The configuration in the <code>routes</code> file means that
     * this method will be called when the application receives a
     * <code>GET</code> request with a path of <code>/</code>.
     */
    public Result index() {
        return ok(
            index.render(
                "Your new application is ready.",
                assetsFinder
            ));
    }
}

as opposed to the current code:

public class HomeController extends Controller {

    /**
     * An action that renders an HTML page with a welcome message.
     * The configuration in the <code>routes</code> file means that
     * this method will be called when the application receives a
     * <code>GET</code> request with a path of <code>/</code>.
     */
    public Result index() {
        return ok(
            index.render(
                "Your new application is ready."
            ));
    }
}

Specially considering the tutorial only highlights very small snippets of the previous code:

Screenshot 2020-01-09 at 12 33 11

The root problem is the code in the tutorial is not the code on the sample app, they are out-of-sync copies.

@mkurz
Copy link
Member

mkurz commented Jan 21, 2020

Fixed by #9982 and playframework/play-samples#83
@ignasi35 please re-open if I am wrong.

@mkurz mkurz closed this as completed Jan 21, 2020
@ignasi35
Copy link
Member

You are not wrong @mkurz. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants