[ 
https://issues.apache.org/struts/browse/WW-1681?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_41540
 ] 

James Holmes commented on WW-1681:
----------------------------------

David, can you supply a patch for this change?

> Reimplement UIBean Key attribute to directly invoke getText rather than 
> utilize ognl
> ------------------------------------------------------------------------------------
>
>                 Key: WW-1681
>                 URL: https://issues.apache.org/struts/browse/WW-1681
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Views
>    Affects Versions: 2.0.3
>            Reporter: David H. DeWolf
>             Fix For: 2.1.0
>
>
> I wrote a simple junit test (below) that tests the 2 techniques for 
> retrieving I18N text.  My numbers for 100 iterations were:
> Using OGNL expression: 476 ms
> Explicitly calling getText: 0 ms
> Yikes!!! There is quite a difference between the two.  The OGNL version takes 
> 5 ms/request compared to almost nothing for the explicit call.  It looks like 
> it would be very beneficial to reimplement the UIBean key lookup code based 
> on the Text component-style of text lookup.  I think the key attribute is a 
> much cleaner way of specifying label text anyway so it's good to give users 
> an incentive to use it. :)
> Tom
> /************ start source code **************/
> package example;
> import java.util.Iterator;
> import junit.framework.TestCase;
> import com.opensymphony.xwork2.ActionSupport;
> import com.opensymphony.xwork2.TextProvider;
> import com.opensymphony.xwork2.util.OgnlValueStack;
> public class TestOgnl extends TestCase {
>    public void testOgnl() {
>        TestAction action = new TestAction();
>        OgnlValueStack stack = new OgnlValueStack();
>        stack.push(action);
>        String value = null;
>        long start = System.currentTimeMillis();
>        for(int i = 0; i < 100; i++) {
>            value = stack.findString("getText('key')");
>        }
>        long end = System.currentTimeMillis();
>        assertEquals("value", value);
>        System.out.println((end - start));
>        start = System.currentTimeMillis();
>        for(int i = 0; i < 100; i++) {
>            value = findString(stack, "key");
>        }
>        end = System.currentTimeMillis();
>        System.out.println((end - start));
>        assertEquals("value", value);
>    }
>    protected String findString(OgnlValueStack stack, String key) {
>        for(Iterator iterator = stack.getRoot().iterator(); iterator
>            .hasNext();) {
>            Object o = iterator.next();
>            if(o instanceof TextProvider) {
>                TextProvider tp = (TextProvider) o;
>                return tp.getText(key);
>            }
>        }
>        return null;
>    }
> }
> class TestAction extends ActionSupport {
>    @Override
>    public String getText(String arg0) {
>        if("key".equals(arg0)) {
>            return "value";
>        }
>        return null;
>    }
> }
> /************ end source code **************/

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to