Announcement Announcement Module
Collapse
No announcement yet.
Creating email content using a templating library Tiles 2 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      Thanks, Marten Deinum.
      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.

      Comment


      • #4
        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).

        Comment

        Working...
        X