You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Numa Schmeder <nu...@euroconsumers.com> on 2006/02/22 17:09:01 UTC

Using tapestry core rendering engine as an email or report generation engine...

Hello,

I would like to create a library based on tapestry to generate email  
or pdf report.  I want to tapestry to generate the html and txt part  
of the email and put them in a mime message using java mail api.  I  
would also like to use tapestry to generate xml reports that can be  
transformed thanks to Jakarta fop in a pdf.  There are plenty of  
tools and libraries to generate email or pdf, but i would like one  
integrated with tapestry as i am working mostly with tapestry, and i  
don't want to learn new tools and have many dependencies.

For  a current web application i use tapestry to generate html only  
email to confirm user registration.
Here is an example on how i do it:
	//the listener that get triggered on form submission

    public void sendEmail(IRequestCycle cycle) {
         ValidationDelegate delegate = (ValidationDelegate)getBeans 
().getBean("delegate");
         if (!delegate.getHasErrors()) {

         EmailForFriend page = (EmailForFriend)cycle.getPage 
("ec:EmailForFriend");
         page.setSenderName(getSenderName());
         page.setRecipientName(getRecipientName());
         page.setComment(getComment());
         page.setProperty((UserInfo) getProperty());

         CharArrayWriter w = new CharArrayWriter();
         PrintWriter pw = new PrintWriter(w);
         HTMLWriter hw = new HTMLWriter(pw);


         cycle.activate(page);
         cycle.renderPage(hw);
         cycle.activate(this);
         setEmailSent(true);
         MailService.sendEmail(getRecipientEmail(),
				"sender@disclosed",
				"---disclosed subject----",
				w.toString());
         }
     }

I don't know if this is correct, it happen to make some bugs when the  
page gets reactivated and you set a property, as property are marked  
dirty?!

I would like an easy way to take a page in a framework or in the  
current web application and render it without polluting the  
RequestCycle. So maybe by using a special RequestCycle, let's call it  
MailCycle.

Example:

HtmlPart part1 = mailCycle.getPage("ec:TestHtmlPart");

TxtPart part2 = mailCycle.getPage("ec:TestTxtPart");

part1.setProperty("myProperty", myProperty);
etc....
part2.setProperty("myProperty", myProperty);
etc...

and then sending the multipart mail using

MimeMessage message = new MimeMessage(session);

etc....

The ultimate goal would be to have a simple library that use tapestry  
and that could be invoked with or without a web server to create an  
email using tapestry template:


TapestryMailService service = new TapestryMailService();
//we set the different properties needed by the templates
service.setProperty("myProperty", myProperty);
//we set the path to the txt template
service.setTxtTemplate("path_to_text.txt");
//we set the path the html template
service.setHtmlTemplate("path_to_html.html");
//we add any other attachment if required
service.addAttachment("path_to_attachment");
service.setSender("sender@test");
service.setRecipient("recipient@Test");
service.setSubject("Sending email using tapestry templating engine is  
great!!!");
service.sendMail();


Maybe i could do something more object oriented :)

Does this sound possible and reasonable, where should i look  to use  
the rendering mechanism of tapestry...
If anyone has already implemented this or has an idea, i would be  
very thankful.

Thanks

Numa





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


Re: Using tapestry core rendering engine as an email or report generation engine...

Posted by Raul Raja Martinez <do...@estudiowebs.com>.
I always use EngineServices to do these kind of things.

Numa Schmeder wrote:
>> De : Numa Schmeder <nu...@euroconsumers.com>
>> Date : 22 février 2006 17:09:01 GMT+01:00
>> À : Tapestry development <ta...@jakarta.apache.org>
>> Objet : Using tapestry core rendering engine as an email or report 
>> generation engine...
>>
>> Hello,
>>
>> I would like to create a library based on tapestry to generate email 
>> or pdf report.  I want to tapestry to generate the html and txt part 
>> of the email and put them in a mime message using java mail api.  I 
>> would also like to use tapestry to generate xml reports that can be 
>> transformed thanks to Jakarta fop in a pdf.  There are plenty of tools 
>> and libraries to generate email or pdf, but i would like one 
>> integrated with tapestry as i am working mostly with tapestry, and i 
>> don't want to learn new tools and have many dependencies.
>>
>> For  a current web application i use tapestry to generate html only 
>> email to confirm user registration.
>> Here is an example on how i do it:
>>     //the listener that get triggered on form submission
>>
>>    public void sendEmail(IRequestCycle cycle) {
>>         ValidationDelegate delegate = 
>> (ValidationDelegate)getBeans().getBean("delegate");
>>         if (!delegate.getHasErrors()) {
>>
>>         EmailForFriend page = 
>> (EmailForFriend)cycle.getPage("ec:EmailForFriend");
>>         page.setSenderName(getSenderName());
>>         page.setRecipientName(getRecipientName());
>>         page.setComment(getComment());
>>         page.setProperty((UserInfo) getProperty());
>>
>>         CharArrayWriter w = new CharArrayWriter();
>>         PrintWriter pw = new PrintWriter(w);
>>         HTMLWriter hw = new HTMLWriter(pw);
>>
>>
>>         cycle.activate(page);
>>         cycle.renderPage(hw);
>>         cycle.activate(this);
>>         setEmailSent(true);
>>         MailService.sendEmail(getRecipientEmail(),
>>                 "sender@disclosed",
>>                 "---disclosed subject----",
>>                 w.toString());
>>         }
>>     }
>>
>> I don't know if this is correct, it happen to make some bugs when the 
>> page gets reactivated and you set a property, as property are marked 
>> dirty?!
>>
>> I would like an easy way to take a page in a framework or in the 
>> current web application and render it without polluting the 
>> RequestCycle. So maybe by using a special RequestCycle, let's call it 
>> MailCycle.
>>
>> Example:
>>
>> HtmlPart part1 = mailCycle.getPage("ec:TestHtmlPart");
>>
>> TxtPart part2 = mailCycle.getPage("ec:TestTxtPart");
>>
>> part1.setProperty("myProperty", myProperty);
>> etc....
>> part2.setProperty("myProperty", myProperty);
>> etc...
>>
>> and then sending the multipart mail using
>>
>> MimeMessage message = new MimeMessage(session);
>>
>> etc....
>>
>> The ultimate goal would be to have a simple library that use tapestry 
>> and that could be invoked with or without a web server to create an 
>> email using tapestry template:
>>
>>
>> TapestryMailService service = new TapestryMailService();
>> //we set the different properties needed by the templates
>> service.setProperty("myProperty", myProperty);
>> //we set the path to the txt template
>> service.setTxtTemplate("path_to_text.txt");
>> //we set the path the html template
>> service.setHtmlTemplate("path_to_html.html");
>> //we add any other attachment if required
>> service.addAttachment("path_to_attachment");
>> service.setSender("sender@test");
>> service.setRecipient("recipient@Test");
>> service.setSubject("Sending email using tapestry templating engine is 
>> great!!!");
>> service.sendMail();
>>
>>
>> Maybe i could do something more object oriented :)
>>
>> Does this sound possible and reasonable, where should i look  to use 
>> the rendering mechanism of tapestry...
>> If anyone has already implemented this or has an idea, i would be very 
>> thankful.
>>
>> Thanks
>>
>> Numa
>>
>>
>>
>>
> 
> 
> ---------------------------------------------------------------------
> 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


Using tapestry core rendering engine as an email or report generation engine...

Posted by Numa Schmeder <nu...@euroconsumers.com>.
> De : Numa Schmeder <nu...@euroconsumers.com>
> Date : 22 février 2006 17:09:01 GMT+01:00
> À : Tapestry development <ta...@jakarta.apache.org>
> Objet : Using tapestry core rendering engine as an email or report  
> generation engine...
>
> Hello,
>
> I would like to create a library based on tapestry to generate  
> email or pdf report.  I want to tapestry to generate the html and  
> txt part of the email and put them in a mime message using java  
> mail api.  I would also like to use tapestry to generate xml  
> reports that can be transformed thanks to Jakarta fop in a pdf.   
> There are plenty of tools and libraries to generate email or pdf,  
> but i would like one integrated with tapestry as i am working  
> mostly with tapestry, and i don't want to learn new tools and have  
> many dependencies.
>
> For  a current web application i use tapestry to generate html only  
> email to confirm user registration.
> Here is an example on how i do it:
> 	//the listener that get triggered on form submission
>
>    public void sendEmail(IRequestCycle cycle) {
>         ValidationDelegate delegate = (ValidationDelegate)getBeans 
> ().getBean("delegate");
>         if (!delegate.getHasErrors()) {
>
>         EmailForFriend page = (EmailForFriend)cycle.getPage 
> ("ec:EmailForFriend");
>         page.setSenderName(getSenderName());
>         page.setRecipientName(getRecipientName());
>         page.setComment(getComment());
>         page.setProperty((UserInfo) getProperty());
>
>         CharArrayWriter w = new CharArrayWriter();
>         PrintWriter pw = new PrintWriter(w);
>         HTMLWriter hw = new HTMLWriter(pw);
>
>
>         cycle.activate(page);
>         cycle.renderPage(hw);
>         cycle.activate(this);
>         setEmailSent(true);
>         MailService.sendEmail(getRecipientEmail(),
> 				"sender@disclosed",
> 				"---disclosed subject----",
> 				w.toString());
>         }
>     }
>
> I don't know if this is correct, it happen to make some bugs when  
> the page gets reactivated and you set a property, as property are  
> marked dirty?!
>
> I would like an easy way to take a page in a framework or in the  
> current web application and render it without polluting the  
> RequestCycle. So maybe by using a special RequestCycle, let's call  
> it MailCycle.
>
> Example:
>
> HtmlPart part1 = mailCycle.getPage("ec:TestHtmlPart");
>
> TxtPart part2 = mailCycle.getPage("ec:TestTxtPart");
>
> part1.setProperty("myProperty", myProperty);
> etc....
> part2.setProperty("myProperty", myProperty);
> etc...
>
> and then sending the multipart mail using
>
> MimeMessage message = new MimeMessage(session);
>
> etc....
>
> The ultimate goal would be to have a simple library that use  
> tapestry and that could be invoked with or without a web server to  
> create an email using tapestry template:
>
>
> TapestryMailService service = new TapestryMailService();
> //we set the different properties needed by the templates
> service.setProperty("myProperty", myProperty);
> //we set the path to the txt template
> service.setTxtTemplate("path_to_text.txt");
> //we set the path the html template
> service.setHtmlTemplate("path_to_html.html");
> //we add any other attachment if required
> service.addAttachment("path_to_attachment");
> service.setSender("sender@test");
> service.setRecipient("recipient@Test");
> service.setSubject("Sending email using tapestry templating engine  
> is great!!!");
> service.sendMail();
>
>
> Maybe i could do something more object oriented :)
>
> Does this sound possible and reasonable, where should i look  to  
> use the rendering mechanism of tapestry...
> If anyone has already implemented this or has an idea, i would be  
> very thankful.
>
> Thanks
>
> Numa
>
>
>
>


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


Re: Using tapestry core rendering engine as an email or report generation engine...

Posted by Jesse Kuhnert <jk...@gmail.com>.
Somehow this thread meandered over to tapestry-dev so I'm correcting it with
this email..

Using an engine service of some kind (like DirectService) is the best way to
do this that I know of.

Like James said though, if you are just building a canned email template
sort of system Velocity is the best choice.

j
On 3/16/06, James Carman <ja...@carmanconsulting.com> wrote:
>
> I think you're trying to force a square peg into a round hole.  Tapestry
> is
> for developing *interactive* html/websites.  You could easily use Velocity
> or some other template engine for a reusable email system.
>
> -----Original Message-----
> From: news [mailto:news@sea.gmane.org] On Behalf Of Sean
> Sent: Thursday, March 16, 2006 4:09 PM
> To: tapestry-dev@jakarta.apache.org
> Subject: Re: Using tapestry core rendering engine as an email or report
> generation engine...
>
> Numa Schmeder <numa <at> euroconsumers.com> writes:
>
> >
> > Hello,
> >
> > I would like to create a library based on tapestry to generate email
> > or pdf report.  I want to tapestry to generate the html and txt part
> > of the email and put them in a mime message using java mail api.
> ...
> > The ultimate goal would be to have a simple library that use tapestry
> > and that could be invoked with or without a web server to create an
> > email using tapestry template:
> >
> > Thanks
> >
> > Numa
> >
>
> I was wondering if you made any progress on this front.  I would like to
> use
>
> tapestry from a service which has no webapp to send HTML emails.
>
> -sean
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org
>
>


--
Jesse Kuhnert
Tacos/Tapestry, team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind.  http://opennotion.com

RE: Using tapestry core rendering engine as an email or report generation engine...

Posted by James Carman <ja...@carmanconsulting.com>.
I think you're trying to force a square peg into a round hole.  Tapestry is
for developing *interactive* html/websites.  You could easily use Velocity
or some other template engine for a reusable email system.

-----Original Message-----
From: news [mailto:news@sea.gmane.org] On Behalf Of Sean
Sent: Thursday, March 16, 2006 4:09 PM
To: tapestry-dev@jakarta.apache.org
Subject: Re: Using tapestry core rendering engine as an email or report
generation engine...

Numa Schmeder <numa <at> euroconsumers.com> writes:

> 
> Hello,
> 
> I would like to create a library based on tapestry to generate email  
> or pdf report.  I want to tapestry to generate the html and txt part  
> of the email and put them in a mime message using java mail api. 
...
> The ultimate goal would be to have a simple library that use tapestry  
> and that could be invoked with or without a web server to create an  
> email using tapestry template:
> 
> Thanks
> 
> Numa
> 

I was wondering if you made any progress on this front.  I would like to use

tapestry from a service which has no webapp to send HTML emails.

-sean




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



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


Re: Using tapestry core rendering engine as an email or report generation engine...

Posted by Sean <se...@sagelogix.com>.
Numa Schmeder <numa <at> euroconsumers.com> writes:

> 
> Hello,
> 
> I would like to create a library based on tapestry to generate email  
> or pdf report.  I want to tapestry to generate the html and txt part  
> of the email and put them in a mime message using java mail api. 
...
> The ultimate goal would be to have a simple library that use tapestry  
> and that could be invoked with or without a web server to create an  
> email using tapestry template:
> 
> Thanks
> 
> Numa
> 

I was wondering if you made any progress on this front.  I would like to use 
tapestry from a service which has no webapp to send HTML emails.

-sean




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


Re: Using tapestry core rendering engine as an email or report generation engine...

Posted by Henri Dupre <he...@gmail.com>.
We implemented something similar for Tapestry 3 and I'm in the process
of converting it to Tapestry 4.
We send Tapestry rendered email pages as email, but we did not use a
service approach. We render the pages during a request and once the
email page is rendered and sent, we leave tapestry render the next
page for the user.
I was thinking about implemting this as a component instead of a
service. I'll have a look though if this could be done as an engine
service. It might be quite nicer.

Henri.



On 2/22/06, Numa Schmeder <nu...@euroconsumers.com> wrote:
> Hello,
>
> I would like to create a library based on tapestry to generate email
> or pdf report.  I want to tapestry to generate the html and txt part
> of the email and put them in a mime message using java mail api.  I
> would also like to use tapestry to generate xml reports that can be
> transformed thanks to Jakarta fop in a pdf.  There are plenty of
> tools and libraries to generate email or pdf, but i would like one
> integrated with tapestry as i am working mostly with tapestry, and i
> don't want to learn new tools and have many dependencies.
>
> For  a current web application i use tapestry to generate html only
> email to confirm user registration.
> Here is an example on how i do it:
>         //the listener that get triggered on form submission
>
>     public void sendEmail(IRequestCycle cycle) {
>          ValidationDelegate delegate = (ValidationDelegate)getBeans
> ().getBean("delegate");
>          if (!delegate.getHasErrors()) {
>
>          EmailForFriend page = (EmailForFriend)cycle.getPage
> ("ec:EmailForFriend");
>          page.setSenderName(getSenderName());
>          page.setRecipientName(getRecipientName());
>          page.setComment(getComment());
>          page.setProperty((UserInfo) getProperty());
>
>          CharArrayWriter w = new CharArrayWriter();
>          PrintWriter pw = new PrintWriter(w);
>          HTMLWriter hw = new HTMLWriter(pw);
>
>
>          cycle.activate(page);
>          cycle.renderPage(hw);
>          cycle.activate(this);
>          setEmailSent(true);
>          MailService.sendEmail(getRecipientEmail(),
>                                 "sender@disclosed",
>                                 "---disclosed subject----",
>                                 w.toString());
>          }
>      }
>
> I don't know if this is correct, it happen to make some bugs when the
> page gets reactivated and you set a property, as property are marked
> dirty?!
>
> I would like an easy way to take a page in a framework or in the
> current web application and render it without polluting the
> RequestCycle. So maybe by using a special RequestCycle, let's call it
> MailCycle.
>
> Example:
>
> HtmlPart part1 = mailCycle.getPage("ec:TestHtmlPart");
>
> TxtPart part2 = mailCycle.getPage("ec:TestTxtPart");
>
> part1.setProperty("myProperty", myProperty);
> etc....
> part2.setProperty("myProperty", myProperty);
> etc...
>
> and then sending the multipart mail using
>
> MimeMessage message = new MimeMessage(session);
>
> etc....
>
> The ultimate goal would be to have a simple library that use tapestry
> and that could be invoked with or without a web server to create an
> email using tapestry template:
>
>
> TapestryMailService service = new TapestryMailService();
> //we set the different properties needed by the templates
> service.setProperty("myProperty", myProperty);
> //we set the path to the txt template
> service.setTxtTemplate("path_to_text.txt");
> //we set the path the html template
> service.setHtmlTemplate("path_to_html.html");
> //we add any other attachment if required
> service.addAttachment("path_to_attachment");
> service.setSender("sender@test");
> service.setRecipient("recipient@Test");
> service.setSubject("Sending email using tapestry templating engine is
> great!!!");
> service.sendMail();
>
>
> Maybe i could do something more object oriented :)
>
> Does this sound possible and reasonable, where should i look  to use
> the rendering mechanism of tapestry...
> If anyone has already implemented this or has an idea, i would be
> very thankful.
>
> Thanks
>
> Numa
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org
>
>


--
Thanks,

Henri.

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