You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jonny Wray <jo...@yahoo.com> on 2004/06/16 19:02:22 UTC

Using DirectService

Hi,

I'm currently in the position of implementing an extension of a class,
or set of classes, that produces an SVG document on a page. The
original implementation follows the image example in the workbench,
defining it's own service and asset. Works fine.

What the extension needs to do is define links within the document that
will activate a listener on the containing page. I thought I could use
the DirectService to get the URLs but my original code is something
along these lines (class has reference to the containing page):
		
IRequestCycle cycle = page.getRequestCycle();
IEngine engine = cycle.getEngine();
IEngineService service = engine.getService("DirectService");	
ILink link = service.getLink(cycle, page.getComponent("form", 
	new Object[]{parameter});
String url = link.getURL();

Now, there are a couple things I don't like about this:

i) It dosen't work as there is no service named "DirectService"
ii) More generally, I don't like the code depending explicitly on the
hardcoded service name.

Anyone have any ideas about a better way of approaching this?
Jonny



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


RE: Using DirectService

Posted by Jonny Wray <jo...@yahoo.com>.
Ah, thanks Howard. And how long have I been using Tapestry now and
didn't know this?

--- "Howard M. Lewis Ship" <hl...@comcast.net> wrote:
> Constants are in the org.apache.tapestry.Tapestry class.
> 
> --
> Howard M. Lewis Ship
> Independent J2EE / Open-Source Java Consultant
> Creator, Jakarta Tapestry
> Creator, Jakarta HiveMind
> http://howardlewisship.com
> 
> 
> > -----Original Message-----
> > From: Jonny Wray [mailto:jonny_wray@yahoo.com] 
> > Sent: Wednesday, June 16, 2004 1:02 PM
> > To: Tapestry users
> > Subject: Using DirectService 
> > 
> > 
> > 
> > Hi,
> > 
> > I'm currently in the position of implementing an extension of a
> class,
> > or set of classes, that produces an SVG document on a page. The
> > original implementation follows the image example in the workbench,
> > defining it's own service and asset. Works fine.
> > 
> > What the extension needs to do is define links within the 
> > document that
> > will activate a listener on the containing page. I thought I could
> use
> > the DirectService to get the URLs but my original code is something
> > along these lines (class has reference to the containing page):
> > 		
> > IRequestCycle cycle = page.getRequestCycle();
> > IEngine engine = cycle.getEngine();
> > IEngineService service = engine.getService("DirectService");	
> > ILink link = service.getLink(cycle, page.getComponent("form", 
> > 	new Object[]{parameter});
> > String url = link.getURL();
> > 
> > Now, there are a couple things I don't like about this:
> > 
> > i) It dosen't work as there is no service named "DirectService"
> > ii) More generally, I don't like the code depending explicitly on
> the
> > hardcoded service name.
> > 
> > Anyone have any ideas about a better way of approaching this?
> > Jonny
> > 
> > 
> > 
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> 
> 


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


RE: NullPointerException in DirectService.getLink

Posted by Jonny Wray <jo...@yahoo.com>.
Hmm, I'm not sure what you mean by not using a Tapestry page. The
service method of my SVGService does get a page from the request cycle
and then passes it's reference to the class that actually produces the
svg image (and contains the code fragments I listed).

I need a url that invokes a listener on the containing page, with
specific data dependent parameters. I thought that means need to use a
DirectService to obtain those URLs.

Looks like I need to go read about services more.

--- "Howard M. Lewis Ship" <hl...@comcast.net> wrote:
> You are implementing a service that does not use a Tapestry page ...
> that's why cycle.getPage()
> returns null.  You might need to use a different service or create
> one of your own to fit your
> needs.
> 
> --
> Howard M. Lewis Ship
> Independent J2EE / Open-Source Java Consultant
> Creator, Jakarta Tapestry
> Creator, Jakarta HiveMind
> http://howardlewisship.com
> 
> 
> > -----Original Message-----
> > From: Jonny Wray [mailto:jonny_wray@yahoo.com] 
> > Sent: Wednesday, June 16, 2004 2:00 PM
> > To: Tapestry users
> > Subject: NullPointerException in DirectService.getLink
> > 
> > 
> > 
> > Hi,
> > 
> > My code:
> > 
> > IRequestCycle cycle = page.getRequestCycle();
> > IEngine engine = cycle.getEngine();
> > IEngineService service =
> engine.getService(Tapestry.DIRECT_SERVICE);
> > ILink link = service.getLink(cycle, form, params);
> > 
> > produces a NPE within getLink. I looked at the code at it's this
> line:
> > 
> > if (complex)
> >    context[i++] = renderPage.getPageName();
> > 
> > I reproduced it directly in my code with:
> > 
> > log.debug("Page: "+cycle.getPage().getPageName());
> > 
> > cycle.getPage() is returning null, and I have no idea why. 
> > I've checked
> > cycle, engine and service. They are not null and returning correct
> > identifying strings. Any ideas as to what I am missing here?
> > 
> > thanks,
> > Jonny
> > 
> > 
> > 
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> 
> 


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


RE: NullPointerException in DirectService.getLink

Posted by "Howard M. Lewis Ship" <hl...@comcast.net>.
You are implementing a service that does not use a Tapestry page ... that's why cycle.getPage()
returns null.  You might need to use a different service or create one of your own to fit your
needs.

--
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind
http://howardlewisship.com


> -----Original Message-----
> From: Jonny Wray [mailto:jonny_wray@yahoo.com] 
> Sent: Wednesday, June 16, 2004 2:00 PM
> To: Tapestry users
> Subject: NullPointerException in DirectService.getLink
> 
> 
> 
> Hi,
> 
> My code:
> 
> IRequestCycle cycle = page.getRequestCycle();
> IEngine engine = cycle.getEngine();
> IEngineService service = engine.getService(Tapestry.DIRECT_SERVICE);
> ILink link = service.getLink(cycle, form, params);
> 
> produces a NPE within getLink. I looked at the code at it's this line:
> 
> if (complex)
>    context[i++] = renderPage.getPageName();
> 
> I reproduced it directly in my code with:
> 
> log.debug("Page: "+cycle.getPage().getPageName());
> 
> cycle.getPage() is returning null, and I have no idea why. 
> I've checked
> cycle, engine and service. They are not null and returning correct
> identifying strings. Any ideas as to what I am missing here?
> 
> thanks,
> Jonny
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 


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


NullPointerException in DirectService.getLink

Posted by Jonny Wray <jo...@yahoo.com>.
Hi,

My code:

IRequestCycle cycle = page.getRequestCycle();
IEngine engine = cycle.getEngine();
IEngineService service = engine.getService(Tapestry.DIRECT_SERVICE);
ILink link = service.getLink(cycle, form, params);

produces a NPE within getLink. I looked at the code at it's this line:

if (complex)
   context[i++] = renderPage.getPageName();

I reproduced it directly in my code with:

log.debug("Page: "+cycle.getPage().getPageName());

cycle.getPage() is returning null, and I have no idea why. I've checked
cycle, engine and service. They are not null and returning correct
identifying strings. Any ideas as to what I am missing here?

thanks,
Jonny



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


RE: Using DirectService

Posted by "Howard M. Lewis Ship" <hl...@comcast.net>.
Constants are in the org.apache.tapestry.Tapestry class.

--
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind
http://howardlewisship.com


> -----Original Message-----
> From: Jonny Wray [mailto:jonny_wray@yahoo.com] 
> Sent: Wednesday, June 16, 2004 1:02 PM
> To: Tapestry users
> Subject: Using DirectService 
> 
> 
> 
> Hi,
> 
> I'm currently in the position of implementing an extension of a class,
> or set of classes, that produces an SVG document on a page. The
> original implementation follows the image example in the workbench,
> defining it's own service and asset. Works fine.
> 
> What the extension needs to do is define links within the 
> document that
> will activate a listener on the containing page. I thought I could use
> the DirectService to get the URLs but my original code is something
> along these lines (class has reference to the containing page):
> 		
> IRequestCycle cycle = page.getRequestCycle();
> IEngine engine = cycle.getEngine();
> IEngineService service = engine.getService("DirectService");	
> ILink link = service.getLink(cycle, page.getComponent("form", 
> 	new Object[]{parameter});
> String url = link.getURL();
> 
> Now, there are a couple things I don't like about this:
> 
> i) It dosen't work as there is no service named "DirectService"
> ii) More generally, I don't like the code depending explicitly on the
> hardcoded service name.
> 
> Anyone have any ideas about a better way of approaching this?
> Jonny
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 


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