Will do. I checked for unit tests on existing result processors like StringResultProcessor and didn't find any, so I wrote it off. I guess most of these are getting exercised in the integration suite?
On 6/7/07, Howard Lewis Ship <[EMAIL PROTECTED]> wrote:
Dan, Good start on your first commit, but you're not done yet ... need to see some tests. Even modifying the integration test suite to have some event handler method return a page class instead of a page name, but testing is mandatory. I do appreciate that you updated the documentation, though. That and some tests and we're all in good shape. Howard On 6/7/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Author: gredler > Date: Thu Jun 7 17:11:23 2007 > New Revision: 545354 > > URL: http://svn.apache.org/viewvc?view=rev&rev=545354 > Log: > TAPESTRY-1370: Add a component event result processor for Class instances > > Added: > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ClassResultProcessor.java > Modified: > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java > tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/event.apt > tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/pagenav.apt > > Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ClassResultProcessor.java > URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ClassResultProcessor.java?view=auto&rev=545354 > ============================================================================== > --- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ClassResultProcessor.java (added) > +++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ClassResultProcessor.java Thu Jun 7 17:11:23 2007 > @@ -0,0 +1,56 @@ > +// Copyright 2007 The Apache Software Foundation > +// > +// Licensed under the Apache License, Version 2.0 (the "License"); > +// you may not use this file except in compliance with the License. > +// You may obtain a copy of the License at > +// > +// http://www.apache.org/licenses/LICENSE-2.0 > +// > +// Unless required by applicable law or agreed to in writing, software > +// distributed under the License is distributed on an "AS IS" BASIS, > +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > +// See the License for the specific language governing permissions and > +// limitations under the License. > + > +package org.apache.tapestry.internal.services; > + > +import org.apache.tapestry.Link; > +import org.apache.tapestry.internal.structure.Page; > +import org.apache.tapestry.runtime.Component; > +import org.apache.tapestry.services.ActionResponseGenerator; > +import org.apache.tapestry.services.ComponentClassResolver; > +import org.apache.tapestry.services.ComponentEventResultProcessor; > + > +/** > + * Used when a component event handler returns a class value. The value is interpreted as the page > + * class. A link to the page will be sent. > + * > + * @see LinkActionResponseGenerator > + */ > +public class ClassResultProcessor implements ComponentEventResultProcessor<Class> > +{ > + private ComponentClassResolver _resolver; > + > + private final RequestPageCache _requestPageCache; > + > + private final LinkFactory _linkFactory; > + > + public ClassResultProcessor(ComponentClassResolver resolver, RequestPageCache requestPageCache, > + LinkFactory linkFactory) > + { > + _resolver = resolver; > + _requestPageCache = requestPageCache; > + _linkFactory = linkFactory; > + } > + > + public ActionResponseGenerator processComponentEvent(Class value, Component component, > + String methodDescripion) > + { > + String className = value.getName(); > + String pageName = _resolver.resolvePageClassNameToPageName(className); > + Page page = _requestPageCache.get(pageName); > + Link link = _linkFactory.createPageLink(page); > + return new LinkActionResponseGenerator(link); > + } > + > +} > > Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java > URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java?view=diff&rev=545354&r1=545353&r2=545354 > ============================================================================== > --- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java (original) > +++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java Thu Jun 7 17:11:23 2007 > @@ -80,6 +80,7 @@ > import org.apache.tapestry.internal.services.BeanBlockSourceImpl; > import org.apache.tapestry.internal.services.BeanModelSourceImpl; > import org.apache.tapestry.internal.services.BindingSourceImpl; > +import org.apache.tapestry.internal.services.ClassResultProcessor; > import org.apache.tapestry.internal.services.ClasspathAssetAliasManagerImpl; > import org.apache.tapestry.internal.services.CommonResourcesInjectionProvider; > import org.apache.tapestry.internal.services.ComponentActionDispatcher; > @@ -1262,7 +1263,7 @@ > public void contributeComponentEventResultProcessor( > @InjectService("ComponentInstanceResultProcessor") > ComponentEventResultProcessor componentInstanceProcessor, > - > + ComponentClassResolver componentClassResolver, > MappedConfiguration<Class, ComponentEventResultProcessor> configuration) > { > configuration.add( > @@ -1288,6 +1289,8 @@ > }); > > configuration.add(String.class, new StringResultProcessor(_requestPageCache, _linkFactory)); > + > + configuration.add(Class.class, new ClassResultProcessor(componentClassResolver, _requestPageCache, _linkFactory)); > > configuration.add(Component.class, componentInstanceProcessor); > > > Modified: tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/event.apt > URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/event.apt?view=diff&rev=545354&r1=545353&r2=545354 > ============================================================================== > --- tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/event.apt (original) > +++ tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/event.apt Thu Jun 7 17:11:23 2007 > @@ -107,7 +107,7 @@ > > You should qualify exactly which component(s) you wish to recieve events from. > > -Event Handler Method Convention Names > +Event Handler Method Convention Names > > As an alternative to the use of annotations, you may name your events in a specific fashion, and Tapestry will invoke your methods just as if > they were annotated. > @@ -128,6 +128,10 @@ > > Note from Howard: I've found that I prefer the naming convention approach, and reserve the annotation just for situations that don't otherwise fit. > > +Event Handler Method Return Values > + > + For page navigation events, the value returned from an event handler method {{{pagenav.html}determines how Tapestry will render a response}}. > + > Event Context > > The context values (the context parameter to the ActionLink component) can be any object. > @@ -154,8 +158,4 @@ > > The event will bubble up the hierarchy, until it is aborted. The event is aborted > when an event handler method returns a non-null value. > - > - For page navigation events, the value returned from an event handler method {{{pagenav.html}determines how Tapestry will render a response}}. > > - > - > \ No newline at end of file > > Modified: tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/pagenav.apt > URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/pagenav.apt?view=diff&rev=545354&r1=545353&r2=545354 > ============================================================================== > --- tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/pagenav.apt (original) > +++ tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/pagenav.apt Thu Jun 7 17:11:23 2007 > @@ -45,15 +45,22 @@ > are transitory, meaningful only while the application is actively engaged, and not meant to be used in later sessions. > > * String response > - > + > When a string is returned, it is expected to be the logical name of a page (as opposed to the page's > fully qualified class name). As elsewhere, the name of the page is case insensitive. > > Again, a render request URL will be constructed and sent to the client as a redirect. > > +* Class response > + > + When a class is returned, it is expected to be a page class. Returning a page class from an event handler is safer for refactoring > + than returning a page name. > + > + As with other response types, a render request URL will be constructed and sent to the client as a redirect. > + > * Page response > - > - You may also return an instance of a page, rather than the name of a page. > + > + You may also return an instance of a page, rather than the name or class of a page. > > A page may be injected via the {{{../apidocs/org/apache/tapestry/annotations/InjectPage.html}InjectPage}} annotation. > > > > -- Howard M. Lewis Ship TWD Consulting, Inc. Independent J2EE / Open-Source Java Consultant Creator and PMC Chair, Apache Tapestry Creator, Apache HiveMind Professional Tapestry training, mentoring, support and project work. http://howardlewisship.com
-- Daniel Gredler http://daniel.gredler.net/
