Uploaded image for project: 'Seam 2'
  1. Seam 2
  2. JBSEAM-3916

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")

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Critical
    • Resolution: Done
    • Affects Version/s: 2.1.0.SP1
    • Fix Version/s: 2.1.2.CR1
    • Component/s: EL
    • Labels:
      None

      Description

      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.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                norman.richards Norman Richards
                Reporter:
                ips Ian Springer
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: