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
Simply
BTW, if you are using Scala,
twittsIfollowshould never be null. Prefer usingOption.