Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to render Map<String, String> to template and use there

i am trying to render a key,value Map to a template and then show there in this way:

@(twittsIfollow: Map[String, String])
 .....
 @if(twittsIfollow != null) {
  @for((key, value) <- twittsIfollow) {
    @key
    @value
   } 
 }

it says, it is wrong. is there a scala tag for Map keys values?

here is my method:

public static Map<String, String> alltwitts(List<Long> otherIDs) {
    Map<String, String> results=new HashMap<String, String>();
    for (Long id: otherIDs) {
        Query selected_twitt = JPA.em().createQuery("select u.twitt from Twitt u where " + " u.whose = ?").setParameter(1, id);
        String twOwner = User.getOneUser(id);
        String twitt  = (String) selected_twitt.getSingleResult();
        results.put(twOwner, twitt);
    }

    return results;
}

then i render to template in this place:

Map<String, String> twittsIfollow = Twitt.alltwitts(IDusersIamFollowing);
return ok(microblog.render(twittsIfollow));

now it is saying: [NonUniqueResultException: result returns more than one elements]

thanks

like image 238
doniyor Avatar asked Jul 27 '26 00:07

doniyor


1 Answers

Simply

@for((key, value) <- twittsIfollow) {
  @key
  @value
}

BTW, if you are using Scala, twittsIfollow should never be null. Prefer using Option.

like image 69
gre Avatar answered Jul 28 '26 14:07

gre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!