You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Patrick Casey <pa...@adelphia.net> on 2005/06/30 23:18:55 UTC

Generate Images on the Fly

 

            I'm having a bit of a brain freeze here and I was hoping
somebody could help me out.

 

            I have a tapestry page with lots of stuff on it. In the middle
of this page, I'm going to need to display a PNG that I'll be generating on
the fly. If it makes it easier, think of it as a chart (although it's
actually not a chart).

 

            Traditionally, with servlets, I returned the main page with a
<img> tag where I wanted the PNG that called back into a special servlet
that built the PNG and served it. So I'd end up with two servlets; one to
build the page and stick the <img> tag in it, the other to actually build
the PNG.

            

            I'm brain freezing on how to do this in tapestry though. The
only solution I've come up with is to use tapestry to build the initial
page, and then write a parallel, 'traditional' servlet that feeds out the
PNG. Is there a better way to go about this? I'm uncomfortable mixing
traditional servlets into the app if I can avoid it.

 

            --- pat


RE: Generate Images on the Fly

Posted by Patrick Casey <pa...@adelphia.net>.
	To be honest, I'm kind of lost when it comes to services. Something
about this aspect of the "tapestry way" is violently alien to my programming
background so I keep getting my head turned sideways when I try to figure
out how the things work. 
	Maybe somebody could help me work my (slow) way through this? And/or
correct any misconceptions I have going in.

	As I understand it, a service does two things:

	 A) It encodes an outbound URL in such a way that, when that URL is
clicked, the same service is invoked on the way back in (with all
appropriate information to act upon it).

	B) It "catches" (I think via a service name match) any inbound
requests and then has to figure out what to do with them. Typically, this
involved handing them off to a component or page to handle, although a
service can handle the request itself if it's so inclined.

	The problem I have is with part A:
	
	How the *heck* does a page embed a link to an arbitrary service into
the outbound HTML stream? What's the magic jwcid/ognl/whatever to invoke the
service's getLink routine? 

	In other words if I have this (skeletal) service:


public class GraphicBuilder extends AbstractService {
	public static final String SERVICE_NAME = "GraphicBuilder";

	public ILink getLink(IRequestCycle cycle, IComponent component,
Object[] parms) {
		String[] context;
		String pageName = component.getPage().getPageName();
		String idPath = component.getIdPath();

		if (idPath != null) {
			context = new String[2];
			context[1] = idPath;
		} else
			context = new String[1];

		context[0] = pageName;
		return constructLink(cycle, SERVICE_NAME, context, parms,
true);
	}

	public void service(IEngineServiceView acrg0, IRequestCycle cycle,
			ResponseOutputStream response) throws
ServletException, IOException {
		Log.info("response");

	}

	public String getName() {

		return SERVICE_NAME;
	}

}

	How do I link it to a page? 

	--- Pat
 
> Sounds like you might need your own "service".  Have a look at the
> workbench sample app, in particular the chart generation. It uses
> JChart, but you can kind of see what you need to do. Look at the
> "ChartService.java" class and you will notice that they are sending an
> image back to the visitors browser.
> 
> 
> --
> 
> Scott F. Walter 	Scott F. Walter
> Principal Consultant
> Vivare, Inc.
> 
> E: scott.walter@vivare.com
> E: scott@scottwalter.com
> Visit scottwalter.com <http://scottwalter.com> --Point.  Click.  Explore!
> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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: Generate Images on the Fly

Posted by "Scott F. Walter" <sc...@scottwalter.com>.
Patrick Casey wrote:

> 
>
>            I'm having a bit of a brain freeze here and I was hoping
>somebody could help me out.
>
> 
>
>            I have a tapestry page with lots of stuff on it. In the middle
>of this page, I'm going to need to display a PNG that I'll be generating on
>the fly. If it makes it easier, think of it as a chart (although it's
>actually not a chart).
>
> 
>
>            Traditionally, with servlets, I returned the main page with a
><img> tag where I wanted the PNG that called back into a special servlet
>that built the PNG and served it. So I'd end up with two servlets; one to
>build the page and stick the <img> tag in it, the other to actually build
>the PNG.
>
>            
>
>            I'm brain freezing on how to do this in tapestry though. The
>only solution I've come up with is to use tapestry to build the initial
>page, and then write a parallel, 'traditional' servlet that feeds out the
>PNG. Is there a better way to go about this? I'm uncomfortable mixing
>traditional servlets into the app if I can avoid it.
>
> 
>
>            --- pat
>
>
>  
>

Sounds like you might need your own "service".  Have a look at the
workbench sample app, in particular the chart generation. It uses
JChart, but you can kind of see what you need to do. Look at the
"ChartService.java" class and you will notice that they are sending an
image back to the visitors browser.


-- 

Scott F. Walter 	Scott F. Walter
Principal Consultant
Vivare, Inc.

E: scott.walter@vivare.com
E: scott@scottwalter.com
Visit scottwalter.com <http://scottwalter.com> --Point.  Click.  Explore!




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