How to display a confirmation message in Tapestry5?
I am developing a website as part of my final year proje开发者_Go百科ct 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.
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.
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
精彩评论