Author: knopp
Date: Mon Jan 14 11:20:30 2008
New Revision: 611898

URL: http://svn.apache.org/viewvc?rev=611898&view=rev
Log:
WICKET-1284

Modified:
    
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
    
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/wicket-ajax.js

Modified: 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java?rev=611898&r1=611897&r2=611898&view=diff
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
 (original)
+++ 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
 Mon Jan 14 11:20:30 2008
@@ -40,6 +40,7 @@
 import org.apache.wicket.markup.html.internal.HtmlHeaderContainer;
 import org.apache.wicket.markup.parser.filter.HtmlHeaderSectionHandler;
 import org.apache.wicket.markup.repeater.AbstractRepeater;
+import org.apache.wicket.protocol.http.WebRequestCycle;
 import org.apache.wicket.protocol.http.WebResponse;
 import org.apache.wicket.request.target.component.IPageRequestTarget;
 import org.apache.wicket.util.string.AppendingStringBuffer;
@@ -1027,5 +1028,18 @@
                        }
                }
                return null;
+       }
+
+       /**
+        * Returns the HTML id of the last focused element.
+        * 
+        * @return
+        */
+       public String getLastFocusedElementId()
+       {
+               String id = 
((WebRequestCycle)RequestCycle.get()).getWebRequest()
+                       .getHttpServletRequest()
+                       .getHeader("Wicket-FocusedElementId");
+               return Strings.isEmpty(id) ? null : id;
        }
 }

Modified: 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/wicket-ajax.js
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/wicket-ajax.js?rev=611898&r1=611897&r2=611898&view=diff
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/wicket-ajax.js 
(original)
+++ 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/wicket-ajax.js 
Mon Jan 14 11:20:30 2008
@@ -825,7 +825,8 @@
                                t.open("GET", url, this.async);
                                t.onreadystatechange = 
this.stateChangeCallback.bind(this);
                                // set a special flag to allow server 
distinguish between ajax and non-ajax requests
-                               t.setRequestHeader("Wicket-Ajax", "true");
+                               t.setRequestHeader("Wicket-Ajax", "true");      
                        
+                               t.setRequestHeader("Wicket-FocusedElementId", 
Wicket.Focus.lastFocusId || "");
                                t.setRequestHeader("Accept", "text/xml");
                                t.send(null);
                                return true;
@@ -872,6 +873,7 @@
                                t.setRequestHeader("Content-Type", 
"application/x-www-form-urlencoded");
                                // set a special flag to allow server 
distinguish between ajax and non-ajax requests
                                t.setRequestHeader("Wicket-Ajax", "true");
+                               t.setRequestHeader("Wicket-FocusedElementId", 
Wicket.Focus.lastFocusId || "");
                                t.setRequestHeader("Accept", "text/xml");
                                t.send(body);
                                return true;
@@ -1918,6 +1920,19 @@
                }
        },
        
+       blur: function(event)
+       { 
+               event = Wicket.fixEvent(event);         
+       
+           // IE doesn't have the property "target".
+           // Use "srcElement" instead.
+           var target = event.target ? event.target : event.srcElement;
+           if (target && Wicket.Focus.lastFocusId==target.id) {
+                       Wicket.Focus.lastFocusId=null;
+                       Wicket.Log.info("focus removed from " + target.id);
+               }
+       },
+       
        setFocusOnId: function(id)
        {
                Wicket.Focus.lastFocusId=id;
@@ -1964,10 +1979,11 @@
        {
                for (var i=0; i< elements.length; i++)
                {
-                   if ( typeof(elements[i].focusSet) == "undefined")
+                   if (elements[i].wicketFocusSet != true)
                    {
                         
Wicket.Event.add(elements[i],'focus',Wicket.Focus.setFocus);
-                        elements[i].focusSet = true;
+                        
Wicket.Event.add(elements[i],'blur',Wicket.Focus.blur);                         
+                        elements[i].wicketFocusSet = true;
                    }
                }
        },


Reply via email to