Cannot render and pass String argument! (Redirect?)

#1

Hello, this error is driving me crazy :slight_smile:

In routes

GET     /                           controllers.VerifyController.index()
GET     /about                      controllers.VerifyController.about()
GET     /verification               controllers.VerifyController.verification()
POST  	/         					controllers.VerifyController.upload(request: Request)

In VerifyController
I am trying to render ok(verification.render(passThisArg)); from upload()
How do I direct to that page and pass the argument or multiple arguments?

    /**
     * This method uses MyMultipartFormDataBodyParser as the body parser
     */
    public Result upload(Http.Request request) {
        Http.MultipartFormData<TemporaryFile> body = request.body().asMultipartFormData();
        Http.MultipartFormData.FilePart<TemporaryFile> certFile = body.getFile("certificate");
        
        if (certFile != null) {
          String fileName = certFile.getFilename();
          long fileSize = certFile.getFileSize();
          String contentType = certFile.getContentType();
          
          	/* The getRef() method gives you a reference to a TemporaryFile. 
             This is the default way Play handles file uploads. */
          	TemporaryFile file = certFile.getRef();

                //How do I pass this argument to render in another page ?
                //The error happens here

	        String passThisArg = "Hello Hello";

          	return ok(verification.render(passThisArg));	 
          
          
        } else {
          return badRequest().flashing("error", "Missing file");
        }
      }

Scala Page - verification.html.scala:
I just need to pass this String object and print it in the view


@(passThisArg: String)

     @layout("Verification ") {

     Hello @passThisArg

}

Scala Page - index.html.scala:
The uploading from index.html works just fine using the Form, here is just a snipped of the code

....
@helper.form(action = routes.VerifyController.upload(), 'enctype -> "multipart/form-data") {

					@helper.CSRF.formField

                .....
}
....

Error from $sbt compile from console

controllers/VerifyController.java:83:1: method render in class views.html.cert.verification cannot be applied to given types;
[error]   required: java.lang.String
[error]   found: no arguments
[error]   reason: actual and formal argument lists differ in length
[error]   return ok(verification.render());
[error]   (Compile / compileIncremental) javac returned non-zero exit code
....

I do appreciate your help and support.

#2

I don’t know, but could be that the badRequest calls the verification page?

(Marcos Pereira) #3

Maybe you have more than one verification.scala.html view and is importing the wrong one?

(Matthias Kurz) #4

Try sbt clean and/or removing your target folder, maybe something got messed up.

(Tim Moore) #5

The error message makes it look like render is being called without arguments from the controller:

[error]   return ok(verification.render());

The source code you posted shows an argument:

          	return ok(verification.render(passThisArg);

…but you only posted part of the file. Could it be called from another method elsewhere in the file?