You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Martin Marinschek <ma...@gmail.com> on 2007/02/13 20:27:49 UTC
Re: svn commit: r507121 - /myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/submitOnEvent/SubmitOnEventRenderer.java
Why does the normal findComponent method fail for you?
regards,
Martin
On 2/13/07, imario@apache.org <im...@apache.org> wrote:
> Author: imario
> Date: Tue Feb 13 09:58:27 2007
> New Revision: 507121
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=507121
> Log:
> use an aggressive strategy (traverse the whole tree) to search a component by id if the normal
> uiComponent.findComponent failed. Is there a better way?
>
>
> Modified:
> myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/submitOnEvent/SubmitOnEventRenderer.java
>
> 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=507121&r1=507120&r2=507121
> ==============================================================================
> --- 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 Tue Feb 13 09:58:27 2007
> @@ -30,6 +30,7 @@
> import javax.faces.component.UIInput;
> import javax.faces.component.UICommand;
> import java.io.IOException;
> +import java.util.Iterator;
>
> /**
> * Attach an event handler to an input element or use a global event handler to
> @@ -74,7 +75,11 @@
> }
>
> forComponent = uiComponent.findComponent(forComponentId);
> - if (forComponent == null)
> + if (forComponent == null)
> + {
> + forComponent = findComponentAggressive(facesContext.getViewRoot(), forComponentId);
> + }
> + if (forComponent == null)
> {
> throw new IllegalArgumentException("SubmitOnEvent: can't find 'for'-component '" + forComponentId + "'");
> }
> @@ -119,4 +124,30 @@
> 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;
> + }
> }
>
>
>
--
http://www.irian.at
Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German
Professional Support for Apache MyFaces
Re: svn commit: r507121 - /myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/submitOnEvent/SubmitOnEventRenderer.java
Posted by Jeff Bischoff <jb...@klkurz.com>.
This "deep scan" seems wrong to me. It could pose both an unnecessary
performance burden and potentially unexpected behaviour. The search
algorithm defined by the UIComponent findComponent method [1] should be
sufficient for specifying a target in any known naming container.
Consider this: A user attempts to reference an object in another naming
container, but makes a mistake in the path portion of the id. This
should cause the search to fail, but thanks to the deep scan, it finds
the desired component by the simple id. Everything appears to work. A
bit later, another user on the team adds a component to another naming
container with the same simple id. All of a sudden, the search is
finding the wrong component to submit - and a JIRA issue probably gets
opened if they can't figure it out.
If we really want to encourage this sort of lazy specification of "for"
attributes, then it needs to be both documented and consistent
throughout the project. My feeling is that findComponent() is sufficient.
[1 tiny] http://tinyurl.com/2k8yzn
[1 long]
http://java.sun.com/javaee/javaserverfaces/1.1_01/docs/api/javax/faces/component/UIComponent.html#findComponent(java.lang.String)
Regards,
Jeff Bischoff
Kenneth L Kurz & Associates, Inc.
Martin Marinschek wrote:
> Why does the normal findComponent method fail for you?
>
> regards,
>
> Martin
>
> On 2/13/07, imario@apache.org <im...@apache.org> wrote:
>> Author: imario
>> Date: Tue Feb 13 09:58:27 2007
>> New Revision: 507121
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=507121
>> Log:
>> use an aggressive strategy (traverse the whole tree) to search a
>> component by id if the normal
>> uiComponent.findComponent failed. Is there a better way?
>>
>>
>> Modified:
>>
>> myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/submitOnEvent/SubmitOnEventRenderer.java
>>
>>
>> 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=507121&r1=507120&r2=507121
>>
>> ==============================================================================
>>
>> ---
>> 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
>> Tue Feb 13 09:58:27 2007
>> @@ -30,6 +30,7 @@
>> import javax.faces.component.UIInput;
>> import javax.faces.component.UICommand;
>> import java.io.IOException;
>> +import java.util.Iterator;
>>
>> /**
>> * Attach an event handler to an input element or use a global event
>> handler to
>> @@ -74,7 +75,11 @@
>> }
>>
>> forComponent = uiComponent.findComponent(forComponentId);
>> - if (forComponent == null)
>> + if (forComponent == null)
>> + {
>> + forComponent =
>> findComponentAggressive(facesContext.getViewRoot(), forComponentId);
>> + }
>> + if (forComponent == null)
>> {
>> throw new IllegalArgumentException("SubmitOnEvent:
>> can't find 'for'-component '" + forComponentId + "'");
>> }
>> @@ -119,4 +124,30 @@
>> 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;
>> + }
>> }
>>
>>
>>
>
>