java - Weird exception while using contains() method -



java - Weird exception while using contains() method -

i'm building web application using spring mvc framework.

i have controller adds attributes (users belonging same team) view, follows:

@requestmapping(value = "/friends", method = requestmethod.get) public modelandview showfriends(principal principal) { modelandview mav = new modelandview("friends"); user currentuser = userservice.finduser(principal.getname()); // method returns collection<long> of userids users belong given team collection<long> userids = findusersfromteam(currentuser.getteam()); mav.addobject("users", userids); mav.addobject("currentuser", userservice.findusers(); homecoming mav; }

and, in "friends.jsp" file, next test:

<c:when test="${users.contains(currentuser.id)}">

which throws next exception:

java.lang.nosuchmethodexception: java.util.arraylist.contains(java.lang.long)

however, arraylist class implements contains(object o) method. what's wrong?

this result of how el parses method expressions , how reflection works

${users.contains(currentuser.id)}

it gets type of users, arraylist, , type of currentuser.id, long. uses reflection method named contains parameter of type long on type arraylist. doesn't find 1 because 1 doesn't exist. remember, reflection not apply inheritance hierarchy checking on parameter list elements.

so though there arraylist#contains(object), there no arraylist#contains(long). hence fails.

don't utilize basic el this. write own el function or logic in handler method.

java spring collections el

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -