You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by David Findley <da...@mac.com> on 2004/09/20 01:36:20 UTC

Custom Service Question

Hello.

I have implemented a custom service (using Jakarta Poi) that returns an 
Excel spreadsheet.

While this works well (and I can pass parameters via the URL), I'd like 
to also be able to treat it similar to a subclass of BasePage.  What I 
mean by that is I'd like to (in a listener method) to get an instance 
of a service, set some properties, and then activate it so that it will 
return the spreadsheet.

Is this the correct way to go about thinking about how to use a service 
like this?  I ask because I have a form that queries a database and can 
return quite a large result set... more than I can pass directly via a 
URL.  Since one of the options for rendering the report can be an Excel 
spreadsheet, I was rather hoping that I could treat it like a page and 
"active" it after setting properties.

I've Googled, looked through the list archives, browsed as much of the 
source as I can figure out, and even read and re-read chapter 8 of 
Tapestry in Action (great book Howard!) in my quest, but I admit to 
being quite stumped.

Any pointers would be greatly appreciated!

Thanks,
David Findley
davidfindley@mac.com


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


Re: Custom Service Question

Posted by Terry Poot <tp...@goldenvoid.com>.
IMHO (newbie to newbie, as it were) is there any reason you can't simply 
use a Tapestry component for this? A service is meant to respond to, and 
completely handle, a user request (i.e. request from the user's 
browser). You just want to do normal page processing, but in the page, 
you want to generate a spreadsheet, right? Other than the code it takes 
to do that, I don't see how that's very different from generating a 
table, or indeed just a string. Now, if you mean you want them to submit 
the form, and the browser immediately starts downloading a spreadsheet 
rather than going to another page, then a service would be good, but if 
you do want a regular page, I don't see the point.

If you want a regular page with a link to download the spreadsheet based 
on the form that was just submitted, I'd do that by collecting the form 
input into a useful object, say in the Visit, and forwarding that to 
another page with a link to a service that generates and downloads the 
spreadsheet directly without leaving that page.

Or maybe I just don't quite get what you're trying to do. I don't 
actually know how you would embed a spreadsheet into a web page, but it 
strikes me as the sort of thing that IE (and only IE) probably can do.

David Findley wrote:

> Eric,
>
> Hi!  Thanks for responding.  I think I understand what you wrote, but 
> I'm still puzzled as to how to "activate" the service itself from the 
> result of a form posting.  It's the reverse direction of the solution 
> you gave.  I'm in a form listener, and I want to "switch control" to a 
> service from inside the listener so I can return an Excel spreadsheet 
> at that point.  (I'm not even sure if that's possible... that's also 
> what I want to determine.)  Here's what I was thinking along the lines 
> of:
>
>     /**
>      * @param cycle
>      */
>     public void formListener(IRequestCycle cycle) {
>         // get the service (like one would get a page)
>         ExcelService exs = (ExcelService) cycle.getEngine().getService(
>                 ExcelService.SERVICE_NAME);
>
>         // set properties of the service
>         
> exs.setSpreadsheetInfo(DataModel.getSpreadsheetInfo(getFormField1(),
>                 getFormField2(), getFormField3()));
>
>         // activate the service, so it returns a spreadsheet directly
>         cycle.activate(exs);
>     }
>
> Of course, this code doesn't work.  In particular, the third line 
> "cycle.activate(exs)" won't compile because activate only takes either 
> a string or an object that implements IPage.  ExcelService is just an 
> object that extends AbstractService.  Also, this code assumes that a 
> service is like a page in that I can get an instance of a service 
> that's all mine for the duration of a cycle... an assumption that I'm 
> not sure is valid.
>
> I think I'm having a conceptual problem.  Given the code sample that 
> illustrates what I'd like to do, what would be a direction I should 
> look in for a solution that fits the Tapestry model?
>
> Thanks,
> David Findley
>
>
> On Sep 19, 2004, at 7:32 PM, Eric Schneider wrote:
>
>> David,
>>
>> I'd create an delegate interface, maybe called IExcelDelegate that 
>> would have a single method like "createSpreadsheet()".
>>
>> Create pages, just like any other Tapestry page, that implement this 
>> interface.
>>
>> public abstract class InventoryReport extends BasePage implements 
>> IExcelDelegate
>>
>> .....
>>
>> public void createSpreadsheet() {
>>     // get big result from database
>> }
>>
>> In your service's service() method call this createSpreadsheet() API 
>> to generate your document.
>>
>> ((IExcelDelegate)cycle.getPage()).createSpreadsheet().
>>
>> Hope that helps.
>> Cheers,
>> e.
>>
>>
>> On Sep 19, 2004, at 7:36 PM, David Findley wrote:
>>
>>> Hello.
>>>
>>> I have implemented a custom service (using Jakarta Poi) that returns 
>>> an Excel spreadsheet.
>>>
>>> While this works well (and I can pass parameters via the URL), I'd 
>>> like to also be able to treat it similar to a subclass of BasePage.  
>>> What I mean by that is I'd like to (in a listener method) to get an 
>>> instance of a service, set some properties, and then activate it so 
>>> that it will return the spreadsheet.
>>>
>>> Is this the correct way to go about thinking about how to use a 
>>> service like this?  I ask because I have a form that queries a 
>>> database and can return quite a large result set... more than I can 
>>> pass directly via a URL.  Since one of the options for rendering the 
>>> report can be an Excel spreadsheet, I was rather hoping that I could 
>>> treat it like a page and "active" it after setting properties.
>>>
>>> I've Googled, looked through the list archives, browsed as much of 
>>> the source as I can figure out, and even read and re-read chapter 8 
>>> of Tapestry in Action (great book Howard!) in my quest, but I admit 
>>> to being quite stumped.
>>>
>>> Any pointers would be greatly appreciated!
>>>
>>> Thanks,
>>> David Findley
>>> davidfindley@mac.com
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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



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


Re: Custom Service Question

Posted by Eric Schneider <er...@centralparksoftware.com>.
Yeah, here is where the the fun stuff starts.

For example, with my custom PDFService I've also created corresponding 
PDFForm and PDFActionLink components.  They're basically exact 
implementations of the regular Tapestry Form and ActionLink components, 
except they use the right service name (service=pdf).

I don't remember the exact details because I don't have the code in 
front of me, but I recall having to duplicate much more code then I 
wanted to (in regards to Form and ActionLink).  A lot of the API was 
declared private, so extending these components was difficult.   There 
might be a better approach, but at the time I just needed it to work.

Cheers,
Eric

On Sep 19, 2004, at 9:41 PM, David Findley wrote:

> Eric,
>
> Hi!  Thanks for responding.  I think I understand what you wrote, but 
> I'm still puzzled as to how to "activate" the service itself from the 
> result of a form posting.  It's the reverse direction of the solution 
> you gave.  I'm in a form listener, and I want to "switch control" to a 
> service from inside the listener so I can return an Excel spreadsheet 
> at that point.  (I'm not even sure if that's possible... that's also 
> what I want to determine.)  Here's what I was thinking along the lines 
> of:
>
> 	/**
> 	 * @param cycle
> 	 */
> 	public void formListener(IRequestCycle cycle) {
> 		// get the service (like one would get a page)
> 		ExcelService exs = (ExcelService) cycle.getEngine().getService(
> 				ExcelService.SERVICE_NAME);
>
> 		// set properties of the service
> 		exs.setSpreadsheetInfo(DataModel.getSpreadsheetInfo(getFormField1(),
> 				getFormField2(), getFormField3()));
>
> 		// activate the service, so it returns a spreadsheet directly
> 		cycle.activate(exs);
> 	}
>
> Of course, this code doesn't work.  In particular, the third line 
> "cycle.activate(exs)" won't compile because activate only takes either 
> a string or an object that implements IPage.  ExcelService is just an 
> object that extends AbstractService.  Also, this code assumes that a 
> service is like a page in that I can get an instance of a service 
> that's all mine for the duration of a cycle... an assumption that I'm 
> not sure is valid.
>
> I think I'm having a conceptual problem.  Given the code sample that 
> illustrates what I'd like to do, what would be a direction I should 
> look in for a solution that fits the Tapestry model?
>
> Thanks,
> David Findley
>
>
> On Sep 19, 2004, at 7:32 PM, Eric Schneider wrote:
>
>> David,
>>
>> I'd create an delegate interface, maybe called IExcelDelegate that 
>> would have a single method like "createSpreadsheet()".
>>
>> Create pages, just like any other Tapestry page, that implement this 
>> interface.
>>
>> public abstract class InventoryReport extends BasePage implements 
>> IExcelDelegate
>>
>> .....
>>
>> public void createSpreadsheet() {
>> 	// get big result from database
>> }
>>
>> In your service's service() method call this createSpreadsheet() API 
>> to generate your document.
>>
>> ((IExcelDelegate)cycle.getPage()).createSpreadsheet().
>>
>> Hope that helps.
>> Cheers,
>> e.
>>
>>
>> On Sep 19, 2004, at 7:36 PM, David Findley wrote:
>>
>>> Hello.
>>>
>>> I have implemented a custom service (using Jakarta Poi) that returns 
>>> an Excel spreadsheet.
>>>
>>> While this works well (and I can pass parameters via the URL), I'd 
>>> like to also be able to treat it similar to a subclass of BasePage.  
>>> What I mean by that is I'd like to (in a listener method) to get an 
>>> instance of a service, set some properties, and then activate it so 
>>> that it will return the spreadsheet.
>>>
>>> Is this the correct way to go about thinking about how to use a 
>>> service like this?  I ask because I have a form that queries a 
>>> database and can return quite a large result set... more than I can 
>>> pass directly via a URL.  Since one of the options for rendering the 
>>> report can be an Excel spreadsheet, I was rather hoping that I could 
>>> treat it like a page and "active" it after setting properties.
>>>
>>> I've Googled, looked through the list archives, browsed as much of 
>>> the source as I can figure out, and even read and re-read chapter 8 
>>> of Tapestry in Action (great book Howard!) in my quest, but I admit 
>>> to being quite stumped.
>>>
>>> Any pointers would be greatly appreciated!
>>>
>>> Thanks,
>>> David Findley
>>> davidfindley@mac.com
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>


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


Re: Custom Service Question

Posted by David Findley <da...@mac.com>.
Eric,

Hi!  Thanks for responding.  I think I understand what you wrote, but 
I'm still puzzled as to how to "activate" the service itself from the 
result of a form posting.  It's the reverse direction of the solution 
you gave.  I'm in a form listener, and I want to "switch control" to a 
service from inside the listener so I can return an Excel spreadsheet 
at that point.  (I'm not even sure if that's possible... that's also 
what I want to determine.)  Here's what I was thinking along the lines 
of:

	/**
	 * @param cycle
	 */
	public void formListener(IRequestCycle cycle) {
		// get the service (like one would get a page)
		ExcelService exs = (ExcelService) cycle.getEngine().getService(
				ExcelService.SERVICE_NAME);

		// set properties of the service
		exs.setSpreadsheetInfo(DataModel.getSpreadsheetInfo(getFormField1(),
				getFormField2(), getFormField3()));

		// activate the service, so it returns a spreadsheet directly
		cycle.activate(exs);
	}

Of course, this code doesn't work.  In particular, the third line 
"cycle.activate(exs)" won't compile because activate only takes either 
a string or an object that implements IPage.  ExcelService is just an 
object that extends AbstractService.  Also, this code assumes that a 
service is like a page in that I can get an instance of a service 
that's all mine for the duration of a cycle... an assumption that I'm 
not sure is valid.

I think I'm having a conceptual problem.  Given the code sample that 
illustrates what I'd like to do, what would be a direction I should 
look in for a solution that fits the Tapestry model?

Thanks,
David Findley


On Sep 19, 2004, at 7:32 PM, Eric Schneider wrote:

> David,
>
> I'd create an delegate interface, maybe called IExcelDelegate that 
> would have a single method like "createSpreadsheet()".
>
> Create pages, just like any other Tapestry page, that implement this 
> interface.
>
> public abstract class InventoryReport extends BasePage implements 
> IExcelDelegate
>
> .....
>
> public void createSpreadsheet() {
> 	// get big result from database
> }
>
> In your service's service() method call this createSpreadsheet() API 
> to generate your document.
>
> ((IExcelDelegate)cycle.getPage()).createSpreadsheet().
>
> Hope that helps.
> Cheers,
> e.
>
>
> On Sep 19, 2004, at 7:36 PM, David Findley wrote:
>
>> Hello.
>>
>> I have implemented a custom service (using Jakarta Poi) that returns 
>> an Excel spreadsheet.
>>
>> While this works well (and I can pass parameters via the URL), I'd 
>> like to also be able to treat it similar to a subclass of BasePage.  
>> What I mean by that is I'd like to (in a listener method) to get an 
>> instance of a service, set some properties, and then activate it so 
>> that it will return the spreadsheet.
>>
>> Is this the correct way to go about thinking about how to use a 
>> service like this?  I ask because I have a form that queries a 
>> database and can return quite a large result set... more than I can 
>> pass directly via a URL.  Since one of the options for rendering the 
>> report can be an Excel spreadsheet, I was rather hoping that I could 
>> treat it like a page and "active" it after setting properties.
>>
>> I've Googled, looked through the list archives, browsed as much of 
>> the source as I can figure out, and even read and re-read chapter 8 
>> of Tapestry in Action (great book Howard!) in my quest, but I admit 
>> to being quite stumped.
>>
>> Any pointers would be greatly appreciated!
>>
>> Thanks,
>> David Findley
>> davidfindley@mac.com
>>
>>
>> ---------------------------------------------------------------------
>> 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: Custom Service Question

Posted by Eric Schneider <er...@centralparksoftware.com>.
David,

I'd create an delegate interface, maybe called IExcelDelegate that 
would have a single method like "createSpreadsheet()".

Create pages, just like any other Tapestry page, that implement this 
interface.

public abstract class InventoryReport extends BasePage implements 
IExcelDelegate

.....

public void createSpreadsheet() {
	// get big result from database
}

In your service's service() method call this createSpreadsheet() API to 
generate your document.

((IExcelDelegate)cycle.getPage()).createSpreadsheet().

Hope that helps.
Cheers,
e.


On Sep 19, 2004, at 7:36 PM, David Findley wrote:

> Hello.
>
> I have implemented a custom service (using Jakarta Poi) that returns 
> an Excel spreadsheet.
>
> While this works well (and I can pass parameters via the URL), I'd 
> like to also be able to treat it similar to a subclass of BasePage.  
> What I mean by that is I'd like to (in a listener method) to get an 
> instance of a service, set some properties, and then activate it so 
> that it will return the spreadsheet.
>
> Is this the correct way to go about thinking about how to use a 
> service like this?  I ask because I have a form that queries a 
> database and can return quite a large result set... more than I can 
> pass directly via a URL.  Since one of the options for rendering the 
> report can be an Excel spreadsheet, I was rather hoping that I could 
> treat it like a page and "active" it after setting properties.
>
> I've Googled, looked through the list archives, browsed as much of the 
> source as I can figure out, and even read and re-read chapter 8 of 
> Tapestry in Action (great book Howard!) in my quest, but I admit to 
> being quite stumped.
>
> Any pointers would be greatly appreciated!
>
> Thanks,
> David Findley
> davidfindley@mac.com
>
>
> ---------------------------------------------------------------------
> 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