Hi, I did try to implement caching of componentTag positions and as a
proof of concept it worked quite well.




Markup.java:

        /**
         * Initialize the index where <head> can be found.
         */
        private void initialize()
        {
                if (markup != null)
                {
                        // Initialize the index where <wicket:extend> can be 
found.
                        for (int i = 0; i < markup.size(); i++)
                        {
                                MarkupElement elem = 
(MarkupElement)markup.get(i);
                                if (elem instanceof WicketTag)
                                {
                                        WicketTag tag = (WicketTag)elem;
                                        if ((tag.isHeadTag() == true) && 
(tag.getNamespace() != null))
                                        {
                                                headerIndex = i;
                                                break;
                                        }
                                }
                        }
                        
                        final String wicketId = 
ComponentTag.DEFAULT_WICKET_NAMESPACE + ":id";
                        Stack markupElements = new Stack();
                        // The path of the current tag
                        String elementsPath = "";
                        // go through the markup and find elements with 
wicket:id and put
their index
                        // to cache
                        for (int i = 0; i < markup.size(); ++i)
                        {
                                MarkupElement elem = (MarkupElement) 
markup.get(i);
                                if (elem instanceof ComponentTag)
                                {
                                        ComponentTag tag = (ComponentTag) elem;
                                        
                                        final boolean hasWicketId = 
tag.getAttributes().containsKey(wicketId);
                                        
                                        // If open tag, put the path of the 
current element onto the
                                        // stack and adjust the path (walk into 
the subdirectory)
                                        if (tag.isOpen() || tag.isOpenClose())
                                        {                               
                                                
markupElements.push(elementsPath);
                                                if (hasWicketId)
                                                {
                                                        if 
(elementsPath.length() > 0)
                                                        {
                                                                elementsPath += 
":";
                                                        }
                                                        elementsPath += 
tag.getAttributes().getString(wicketId);
                                                        
indexCache.put(elementsPath, new Integer(i));                                   
        
                                                }                               
                
                                        }
                                        if (tag.isClose() || tag.isOpenClose())
                                        {
                                                // return to the parent 
"directory"
                                                elementsPath = 
(String)markupElements.pop();
                                        }
                                }
                        }
                }
        }

The findComponentIndex just returns the value from cache. Which IMHO
is better then traversing the whole markup every time.

The problem I couldn't solve is the numbers in component paths
(repeaters). Maybe there really should be a rule "no numbers only
wicket:id"?

Haven't tested this with border yet, I wonder what will go wrong.

-Matej


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
Wicket-develop mailing list
Wicket-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-develop

Reply via email to