1

I am using the Java Play Framework and trying to pass array values from controller to view, but I got error. My code is here:

public class Application extends Controller {
    public static Result index() {
        String s= "Hello Mr.View";
        String st[] = {"firstValue","second","third","fourth"};
        return ok(index.render(st));
     }
}     

and my template is:

@(message: String)
 @import helper._
    @import models._
    @import java.sql._
              <h1>@message </hl>     

How can I resolve this error?

1 Answer 1

1

You need to declare the parameter as a String-Array. I'm assuming you use the default templating system of the framework. It should look something like this:

@(message: Array[String])
 @import helper._
    @import models._
    @import java.sql._
              <h1>@message </hl>     
Sign up to request clarification or add additional context in comments.

3 Comments

thanks its working is it possible to pass sql query values from controller to view.
Yes this should be possible. Although you might want to consider to pass an array of Strings or an array of of your model-class. The Play Framework suggests to create a model class for your database which handles the queries, etc and provides CRUD functionality. You coud pass Arrays of those objects. (just change the type of the Parameter to Array[models.YourModel]
Kindly see this link here i trying someting with sql in controller i got error i mention here detaild please see the link and help me stackoverflow.com/questions/19590140/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.