You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by im...@apache.org on 2007/02/15 11:36:46 UTC

svn commit: r507879 - in /myfaces/tomahawk/trunk: core/src/main/java/org/apache/myfaces/custom/calendar/ sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ sandbox/core/src/main/java/org/apache/myfaces/custom/focus/ sandbox/core/src/mai...

Author: imario
Date: Thu Feb 15 02:36:45 2007
New Revision: 507879

URL: http://svn.apache.org/viewvc?view=rev&rev=507879
Log:
added findDeepComponentById to ComponentUtils. Using it in s:focus and s:submitOnEvent as "fallback" if normal findComponent failes

Modified:
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/Conversation.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/focus/HtmlFocus.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/focus/HtmlFocusRenderer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/submitOnEvent/SubmitOnEventRenderer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/util/ComponentUtils.java

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java?view=diff&rev=507879&r1=507878&r2=507879
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java Thu Feb 15 02:36:45 2007
@@ -375,7 +375,7 @@
             if(inputCalendar.getPopupTodayDateFormat()!=null)
                 setStringVariable(script, popupCalendarVariable+".initData.todayDateFormat",inputCalendar.getPopupTodayDateFormat());
             else if(inputCalendar.getPopupDateFormat() != null)
-                setStringVariable(script, popupCalendarVariable+".initData.todayDateFormat",inputCalendar.getPopupDateFormat());                
+                setStringVariable(script, popupCalendarVariable+".initData.todayDateFormat",inputCalendar.getPopupDateFormat());
             if(inputCalendar.getPopupWeekString()!=null)
                 setStringVariable(script, popupCalendarVariable+".initData.weekString",inputCalendar.getPopupWeekString());
             if(inputCalendar.getPopupScrollLeftMessage()!=null)
@@ -917,7 +917,7 @@
             {
                 String popupDateFormat = ((HtmlInputCalendar) uiComponent).getPopupDateFormat();
 
-                dateFormat = new SimpleDateFormat(createJSPopupFormat(facesContext, popupDateFormat));
+                dateFormat = new SimpleDateFormat(createJSPopupFormat(facesContext, popupDateFormat), facesContext.getViewRoot().getLocale());
             }
             else
             {
@@ -968,7 +968,7 @@
             {
                 String popupDateFormat = ((HtmlInputCalendar) uiComponent).getPopupDateFormat();
 
-                dateFormat = new SimpleDateFormat(createJSPopupFormat(facesContext, popupDateFormat));
+                dateFormat = new SimpleDateFormat(createJSPopupFormat(facesContext, popupDateFormat), facesContext.getViewRoot().getLocale());
             }
             else
             {
@@ -989,7 +989,7 @@
             if(dateFormat instanceof SimpleDateFormat)
                 return (SimpleDateFormat) dateFormat;
             else
-                return new SimpleDateFormat("dd.MM.yyyy");
+                return new SimpleDateFormat("dd.MM.yyyy", facesContext.getViewRoot().getLocale());
         }
 
     }

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/Conversation.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/Conversation.java?view=diff&rev=507879&r1=507878&r2=507879
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/Conversation.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/Conversation.java Thu Feb 15 02:36:45 2007
@@ -18,16 +18,14 @@
  */
 package org.apache.myfaces.custom.conversation;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.faces.context.FacesContext;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.TreeMap;
 
-import javax.faces.context.FacesContext;
-import javax.faces.el.ValueBinding;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 /**
  * handle conversation related stuff like beans
  * @author imario@apache.org
@@ -156,7 +154,7 @@
 	 */
 	public boolean isPersistence()
 	{
-		return persistence;
+		return persistence || persistenceManager != null;
 	}
 
 	public PersistenceManager getPersistenceManager()
@@ -167,5 +165,13 @@
 		}
 
 		return persistenceManager;
+	}
+
+	/**
+	 * returns true if we hold the given instance
+	 */
+	public boolean hasBean(Object instance)
+	{
+		return beans.containsValue(instance);
 	}
 }

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java?view=diff&rev=507879&r1=507878&r2=507879
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java Thu Feb 15 02:36:45 2007
@@ -211,6 +211,27 @@
 	}
 
 	/**
+	 * find the conversation which holds the given instance
+	 */
+	public Conversation findConversation(Object instance)
+	{
+		synchronized (mutex)
+		{
+			touch();
+			Iterator iterConversations = conversations.values().iterator();
+			while (iterConversations.hasNext())
+			{
+				Conversation conversation = (Conversation) iterConversations.next();
+				if (conversation.hasBean(instance))
+				{
+					return conversation;
+				}
+			}
+		}
+		return null;
+	}
+
+	/**
 	 * inject all beans from the conversation context to their configured scope
 	protected void injectConversationBeans(FacesContext context)
 	{

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java?view=diff&rev=507879&r1=507878&r2=507879
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java Thu Feb 15 02:36:45 2007
@@ -309,6 +309,21 @@
 	}
 
 	/**
+	 * Find the conversation which holds the given instance
+	 *
+	 * @return null if no conversation context is active or if the conversation did not exist.
+	 */
+	public Conversation findConversation(Object instance)
+	{
+		ConversationContext conversationContext = getConversationContext();
+		if (conversationContext == null)
+		{
+			return null;
+		}
+		return conversationContext.findConversation(instance);
+	}
+
+	/**
 	 * check if the given conversation is active
 	 */
 	public boolean hasConversation(String name)

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/focus/HtmlFocus.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/focus/HtmlFocus.java?view=diff&rev=507879&r1=507878&r2=507879
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/focus/HtmlFocus.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/focus/HtmlFocus.java Thu Feb 15 02:36:45 2007
@@ -20,6 +20,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.custom.util.ComponentUtils;
 
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIComponentBase;
@@ -86,6 +87,10 @@
 		}
 
 		UIComponent forComp = findComponent(forStr);
+		if (forComp == null)
+		{
+			forComp = ComponentUtils.findDeepComponentById(getFacesContext().getViewRoot(), forStr);
+		}
 		if (forComp == null)
 		{
 			log.warn("could not find UIComponent referenced by attribute focus@for = '"

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/focus/HtmlFocusRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/focus/HtmlFocusRenderer.java?view=diff&rev=507879&r1=507878&r2=507879
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/focus/HtmlFocusRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/focus/HtmlFocusRenderer.java Thu Feb 15 02:36:45 2007
@@ -75,7 +75,7 @@
 
             writer.startElement(HTML.SCRIPT_ELEM, uiComponent);
             writer.writeAttribute(HTML.SCRIPT_TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
-            writer.writeText("setTimeout(\"document.getElementById('" + clientId + "').focus()\", 0)", null);
+            writer.writeText("setTimeout(\"document.getElementById('" + clientId + "').focus()\", 100)", null);
             writer.endElement(HTML.SCRIPT_ELEM);
 
 			if (focus.isRememberClientFocus())

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/submitOnEvent/SubmitOnEventRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/submitOnEvent/SubmitOnEventRenderer.java?view=diff&rev=507879&r1=507878&r2=507879
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/submitOnEvent/SubmitOnEventRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/submitOnEvent/SubmitOnEventRenderer.java Thu Feb 15 02:36:45 2007
@@ -23,6 +23,7 @@
 import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
 import org.apache.myfaces.renderkit.html.util.AddResource;
 import org.apache.myfaces.renderkit.html.util.ResourcePosition;
+import org.apache.myfaces.custom.util.ComponentUtils;
 
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
@@ -77,7 +78,7 @@
             forComponent = uiComponent.findComponent(forComponentId);
 			if (forComponent == null)
 			{
-				forComponent = findComponentAggressive(facesContext.getViewRoot(), forComponentId);
+				forComponent = ComponentUtils.findDeepComponentById(facesContext.getViewRoot(), forComponentId);
 			}
 			if (forComponent == null)
             {
@@ -124,30 +125,4 @@
         out.writeText(js.toString(), null);
         out.endElement(HTML.SCRIPT_ELEM);
     }
-
-	/**
-	 * deep scan the tree and see if ANY naming container has a component with the
-	 * given id
-	 */
-	private UIComponent findComponentAggressive(UIComponent base, String id)
-	{
-		if (id.equals(base.getId()))
-		{
-			return base;
-		}
-
-		Iterator iter = base.getFacetsAndChildren();
-		while (iter.hasNext())
-		{
-			UIComponent child = (UIComponent) iter.next();
-
-			UIComponent found = findComponentAggressive(child, id);
-			if (found != null)
-			{
-				return found;
-			}
-		}
-
-		return null;
-	}
 }

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/util/ComponentUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/util/ComponentUtils.java?view=diff&rev=507879&r1=507878&r2=507879
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/util/ComponentUtils.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/util/ComponentUtils.java Thu Feb 15 02:36:45 2007
@@ -19,11 +19,10 @@
 
 package org.apache.myfaces.custom.util;
 
-import java.util.Iterator;
-
 import javax.faces.component.UIComponent;
 import javax.faces.component.html.HtmlMessages;
 import javax.faces.context.FacesContext;
+import java.util.Iterator;
 
 /**
  * User: treeder
@@ -32,9 +31,9 @@
  */
 public final class ComponentUtils
 {
-	
+
 	private ComponentUtils(){
-		
+
 	}
 
     /**
@@ -94,7 +93,33 @@
     }
 
 
-    public static UIComponent findFirstMessagesComponent(FacesContext context, UIComponent base)
+	/**
+	 * deep scan the tree and see if ANY naming container has a component with the
+	 * given id
+	 */
+	public static UIComponent findDeepComponentById(UIComponent base, String id)
+	{
+		if (id.equals(base.getId()))
+		{
+			return base;
+		}
+
+		Iterator iter = base.getFacetsAndChildren();
+		while (iter.hasNext())
+		{
+			UIComponent child = (UIComponent) iter.next();
+
+			UIComponent found = findDeepComponentById(child, id);
+			if (found != null)
+			{
+				return found;
+			}
+		}
+
+		return null;
+	}
+
+	public static UIComponent findFirstMessagesComponent(FacesContext context, UIComponent base)
     {
         if (base == null)
         {
@@ -121,5 +146,5 @@
         return null;
     }
 
-   
+
 }