You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Numa Schmeder <nu...@euroconsumers.com> on 2006/02/22 19:10:19 UTC
Using tapestry core rendering engine as an email or report generation engine...
> 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 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