Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-4546

Caching of EL method invocations

XMLWordPrintable

    • ZK 9.5.0 S1
    • None

      Steps to Reproduce

      compare: calling a bean method via EL using a matching or non matching parameter type

      1) calling concat(String)

              <label value="${'asdf'.concat('astring')}"/>
      

      2) calling concat(Long)

              <label value="${'asdf'.concat(1234)}"/>
      

      Current Result

      case 1) will identify the method directly and invoke it efficiently

      case 2) will fail to find the method initially throw/catch a MethodNotFound exception, and then loop through all available methods on the class until it finds a potential match
      (this exception + loop happens every time)

      Expected Result

      ideally a matching method should be cached (if efficiently possible)
      avoiding the exception and the loop

      Debug Information

      https://github.com/zkoss/zk/blob/v9.0.0/zel/src/org/zkoss/zel/BeanELResolver.java#L209-L222

      Workaround

      for the String.concat case use the concatenation '+=' operator

              <label value="${'asdf' += 1234}"/>
              <!-- for data binding extra parentheses are required -->
              <label value="@init(('asdf' += 1234))"/>
              <label value="@load(('asdf' += 1234))"/>
      

      Avoid calling methods by implementing dedicated bean getters:

              <label value="@init(vm.buildFullName(person))"/>
              <!-- can be replaced by -->
              <label value="@init(person.fullName)"/>
      

      and implement a getFullName method on the bean class

            DevChu DevChu
            cor3000 cor3000
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 1 day
                1d
                Remaining:
                Remaining Estimate - 1 day
                1d
                Logged:
                Time Spent - Not Specified
                Not Specified