]
Norman Richards reassigned JBSEAM-3916:
---------------------------------------
Assignee: Norman Richards
SeamELResolver.resolveInMap() will resolve a property
"size" to ((Map)base).size() even if the Map contains a key named
"size" - instead, it should return null and allow javax.el.MapELResolver to
resolve the property to ((Map)base).get("size")
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Key: JBSEAM-3916
URL:
https://jira.jboss.org/jira/browse/JBSEAM-3916
Project: Seam
Issue Type: Bug
Components: EL
Affects Versions: 2.1.0.SP1
Reporter: Ian Springer
Assignee: Norman Richards
Priority: Critical
I have an expression:
#{MyBean.someMap['size']}
In my non-Seam JSF app, this expression was resolving to
MyBean.getSomeMap().get("size"). However, when I integrated Seam into my app,
the expression started instead resolving to MyBean.getSomeMap().size(), which broke my
app. This is occurring because SeamELResolver is ahead of javax.el.MapELResolver in the
CompositeELResolver resolver list, and its resolveInMap() function ensures a property
named "size" resolves to ((Map)base).size() This makes it impossible for me to
obtain the value of the element with key "size" from my Map via EL.
To solve this, I suggest changing SeamELResolver.resolveInMap() to the following:
private Object resolveInMap(ELContext context, Object base, Object property)
{
if ( !( (Map) base ).containsKey("size") &&
"size".equals(property) )
{
context.setPropertyResolved(true);
return ( (Map) base ).size();
}
else if ( !( (Map) base ).containsKey("values") &&
"values".equals(property) )
{
context.setPropertyResolved(true);
return ( (Map) base ).values();
}
else if ( !( (Map) base ).containsKey("keySet") &&
"keySet".equals(property) )
{
context.setPropertyResolved(true);
return ( (Map) base ).keySet();
}
else if ( !( (Map) base ).containsKey("entrySet") &&
"entrySet".equals(property) )
{
context.setPropertyResolved(true);
return ( (Map) base ).entrySet();
}
else
{
return null;
}
}
The only disadvantage of this is that if you actually are trying to get at map.size(),
there will be no way to do so if the Map happens to contain a key named "size".
However, in such a case, #{MyBean.someMap.keySet.size} or #{MyBean.someMap.values.size}
could instead be used to obtain the Map's size.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: