0

I have been trying it for sometime and I have to create view for complex frontend application. This looks like I am able to send array list like:

In Controller :

ArrayList<String> cname = new ArrayList<>();
cname.add("akshay");
cname.add("david");

And in View :

@(cname: List[String])

But, now I have to create an array of this array. This could be other data structure as well like List, but for now I have to pass an array of array, which looks like :

ArrayList<ArrayList<String>> arr = new ArrayList<>();

What type should be view then ? Below is not working :

@(cname : List[List[String]])

Any reference to tutorial/guide for such arrays for future reference would be much helpful.

Edit :

I need to pass ArrayList of ArrayList. The program in question is :

while(rs.next())
        {
            cname = rs.getString("customername");
            cmobile = rs.getString("customermobile");
            amount = rs.getString("billamount");

            namearr.add(cname);
            mobilearr.add(cmobile);
            amountarr.add(amount);

        }
        rowsArray.add(mobilearr);
        rowsArray.add(namearr);
        rowsArray.add(amountarr);

And I have to send rowsArray to front. I know using this kind of queries is abuse of Play Framework, but in this case, I had to go as native as possible. Is there any otherway I can send such data to frontend except JPA ? Is it possible that I create a class with these arrays and then in my controller create array of objects and send it to view ?

1

2 Answers 2

2

You need the fully qualified class names since Scala has its own list type that shadows the Java list or is not imported automatically.

Use

@(cname : java.util.List[java.util.List[String]])

for

List<List<String>> arr = new ArrayList<>();

or

@(cname : java.util.ArrayList[java.util.ArrayList[String]])

for

ArrayList<ArrayList<String>> arr = new ArrayList<>();

But the code could be more cleaner if you use types (new classes) for your data.

Sign up to request clarification or add additional context in comments.

1 Comment

so this should be applied for Collections as well.
0

List references to the scala type : List and not the java super type java.util.List. I have never used the Java version of Playframework but you should try to pass : ArrayList[ArrayList[String]].

Comments

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.