shane87
shane87

Reputation: 3120

How to display a confirmation message in Tapestry5?

I am developing a website as part of my final year project and I want to display a message which confirms that an email has been sent.

I know how to display custom error messages on a form i.e. You cannot go any further until the following errors are fixed : login name not known!

I want to display a message which will say: your email has been sent! after I send an email. I have been told that I should display this message through the flash.

I am unsure on how to do this, any help would be greatly appreciated.

Upvotes: 3

Views: 2325

Answers (2)

balapal
balapal

Reputation: 41

Since Tapestry 5.3 you can use the Alerts component.

Template:

<t:alerts />

Page class:

@Inject
private AlertManager alertManager;

@OnEvent(EventConstants.SUCCESS)
void onSendMessage() {
     ...
     this.alertManager.success("Your message was sent.");
}

Jumpstart has an example of it. You can play around with it at http://jumpstart.doublenegative.com.au/jumpstart7/examples/component/alerts

Upvotes: 0

Henning
Henning

Reputation: 16311

The simplest thing to do would be to show a conditional message on the page displayed when the message was sent, like:

<span t:type="If" t:test="messageSent">Your message was sent.</span>

Page class snippet:

@Persist(PersistenceConstants.FLASH)
private boolean messageSent;


public boolean isMessageSent() {
    return this.messageSent;
}

@OnEvent(EventConstants.SUCCESS)
void onSendMessage() {
    ...
    this.messageSent = true;
}

If you have other places in your code where you'd like to display messages, or if you'd like to do some fancy AJAX, creating a messages component to add to your layout might be an option.

Upvotes: 2

Related Questions