You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Kevin Whitley <ke...@podtech.net> on 2006/11/06 06:08:05 UTC

Re: Overriding HomeService (this works)

Thanks for the help.  Just to complete the loop for anybody who is  
interested in doing something similar...

This configuration worked for me (added to my hivemodule.xml):

     <implementation service-id="tapestry.services.Home">
         <invoke-factory service-id="hivemind.BuilderFactory"  
model="singleton">
             <construct class="xx.tapestry.MyHomeService">
                 <set-object property="responseRenderer"  
value="infrastructure:responseRenderer" />
                 <set-object property="linkFactory"  
value="infrastructure:linkFactory" />
                 <set-object property="pageName" value="app- 
property:org.apache.tapestry.home-page" />
             </construct>
         </invoke-factory>
     </implementation>


Where I had the class "MyHomeService" with code like this:

------------------------------------------------------------------------ 
----------
package xx.tapestry;

import org.apache.tapestry.engine.HomeService;
import org.apache.tapestry.services.ResponseRenderer;
import org.apache.tapestry.IRequestCycle;

import java.io.IOException;

/**
     Example override of Tapestry's HomeService
*/
public class MyHomeService extends HomeService
{

     private String _defaultPageName;
     private ResponseRenderer _responseRenderer;

     public void setResponseRenderer (ResponseRenderer responseRenderer)
     {
         _responseRenderer = responseRenderer;
         super.setResponseRenderer(responseRenderer);
     }

     public void setPageName (String pageName)
     {
         super.setPageName(pageName);
         _defaultPageName = pageName;
     }

     public String getPageName ()
     {
         // replace with interesting logic
         return "_defaultPageName;
     }

     public void service(IRequestCycle cycle) throws IOException
     {
         // copied from HomeService (because no way to reuse that code)
         cycle.activate(getPageName());

         _responseRenderer.renderResponse(cycle);
     }

------------------------------------------------------------------------ 
----------


Thanks,
Kevin Whitley
podtech.net





On Nov 3, 2006, at 1:35 PM, James Carman wrote:

> You might have to inject the same things that the regular home service
> has injected.  Take a look at the HiveDoc for HomeService.
>
> On 11/3/06, Kevin Whitley <ke...@podtech.net> wrote:
>> Thanks - that gets the service instantiated.  However, I discover
>> that my service doesn't get initialized the same way that the regular
>> HomeService does.
>>
>> Without my implementation xml in place the standard HomeService gets
>> initialized (calls to setResponseRenderer() and setPageName()) when
>> it is referenced in
>> tapestry.services.impl.ServiceMapImpl.resolveEngineService().  But
>> when I've got my MyHomeService in place that same routine does not
>> result in the calls to setResponseRenderer and setPageName - which
>> basically makes it impossible to work.  Huh?  I would have thought
>> that the service would have been treated the same - is there more
>> configuration I have to set up somewhere?
>>
>> Thanks,
>> Kevin Whitley
>> podtech.net
>>
>>
>> On Nov 3, 2006, at 11:03 AM, James Carman wrote:
>>
>> > Try this:
>> >
>> > <implementation service-id="tapestry.services.Home">
>> >  <invoke-factory>
>> >    <construct class="net.podtech.ui.tapestry.MyHomeService"/>
>> >  </invoke-factory>
>> > </implementation>
>> >
>> > On 11/3/06, Kevin Whitley <ke...@podtech.net> wrote:
>> >> In Tapestry 4.0 I'd like to override the HomeService (varying the
>> >> home page depending on the user - unfortunately not as simple as
>> >> merely changing the home page name).  Javadoc comments in  
>> HomeService
>> >> make it sound like this is expected and trivial.
>> >>
>> >> I created a test class to try this out - MyHomeService.  And  
>> then in
>> >> my hivemodule.xml file I have:
>> >>
>> >> <module id="podtech" version="1.0.0"
>> >> package="net.podtech.ui.tapestry.Xx">
>> >>      <implementation service-id="home">
>> >>          <create-instance
>> >> class="net.podtech.ui.tapestry.MyHomeService"/>
>> >>      </implementation>
>> >> </module>
>> >>
>> >> But when HiveMind is initializing I get complaints that "Module
>> >> podtech contributed to unknown service point podtech.home".  On a
>> >> guess I tried changing the service-id to "tapestry.home" but I got
>> >> the same error ("unknown service point tapestry.home").
>> >>
>> >> I'm basing the service-override on the HiveMind "overriding a  
>> service
>> >> doc" at http://hivemind.apache.org/override.html.  Is this the  
>> right
>> >> approach?  hivemodule.xml the right place?  What is the service-id
>> >> that is needed?  Do I need to have this in a particular  
>> module?  (Is
>> >> there some way to ask HiveMind for an enumeration of legal service
>> >> points?)
>> >>
>> >> By the way, once I get my HomeService hooked in, I assume that
>> >> overriding the getPageName() method will be all I need to do to
>> >> redirect to different pages?
>> >>
>> >> Thanks for any advice,
>> >> Kevin Whitley
>> >> Podtech.net
>> >>
>> >>
>> >>
>> >>  
>> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> >> For additional commands, e-mail: users-help@tapestry.apache.org
>> >>
>> >>
>> >
>> >  
>> ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> > For additional commands, e-mail: users-help@tapestry.apache.org
>> >
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org