Results 1 to 4 of 4

Thread: Creating email content using a templating library Tiles 2

  1. #1
    Join Date
    Aug 2008
    Posts
    2

    Default Creating email content using a templating library Tiles 2

    At the reference I found a velocity-based example to create email content:
    chapter 22.3.2.1:
    Code:
       private void sendConfirmationEmail(final User user) {
          MimeMessagePreparator preparator = new MimeMessagePreparator() {
             public void prepare(MimeMessage mimeMessage) throws Exception {
                MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
                message.setTo(user.getEmailAddress());
                message.setFrom(emailstring); 
                Map model = new HashMap();
                model.put("user", user);
                String text = VelocityEngineUtils.mergeTemplateIntoString(
                   velocityEngine, "com/dns/registration-confirmation.vm", model);
                message.setText(text, true);
             }
          };
          this.mailSender.send(preparator);
       }
    Can I do this with Apache Tiles 2. If so, how?

    Thank you,
    movieluvr

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Tiles is completly different framework then velocity, whereas velocity is quite unaware of the underlying technology, Tiles is designed and build for web applications. So creating some email content with Tiles is going to be hard.

    You would first have to create a tiles definition, render the jsp and use the output of the rendering as content for the email.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Aug 2008
    Posts
    2

    Default

    Thanks, Marten Deinum.
    Quote Originally Posted by Marten Deinum View Post
    You would first have to create a tiles definition, render the jsp and use the output of the rendering as content for the email.
    Definitively, that is the approach. But a small snippet or a list of the involved objects would help very much. I found a class called TileDefinition that could be used like that (pseudo code):
    Code:
    TileDefinition td = getTilesApplicationContext().get("defname");
    String text = td.anyhowRender(map);
    mail.setMessage(text);
    But I do not know the exact code for the first and second line.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    The problem is tha tyou will need to delegate to your servlet engine, that is the only thing that can render a JSP. So after delegating you will need to retrieve the generated output. That is why it is complicated.

    As I stated Tiles is designed for web pages it isn't designed as a general templating engine (as Velocity or Freemarker).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •