Nice, that seems in line with what I'm seeing as well now. I still think this is worth improving, as those 5ms can add up on larger forms.

Tom Schneider wrote:
Well, I guess I was feeling more ambitious than I thought.

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.

Agreed.  I've created:

https://issues.apache.org/struts/browse/WW-1681


 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 **************/

Ted Husted wrote:

The tags now have a "key" attribute that can be used in place of the
getText OGNL expression.

I'd be curious to know if

<s:textfield key="lastName" />

runs faster than

<s:textfield label="%getText('lastName')" name="lastName" />

If so, I wonder if there other places where we could eliminate common
OGNL statements by adding functionality to the tags.

-Ted.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to