tags:

views:

380

answers:

1

I have a bunch of Seam form pages; each has a command button that calls a sendEmail() method in a custom utility class. The method looks like this:

public String sendEmail(String mailFile) throws SMTPSendFailedException {
    status = "Processing email now...";
    renderer.render(mailFile);
    status = "Email sent successfully."; 
    renderer = null;

    return "/index.xhtml";
}

The button looks like this:

<a4j:commandButton action="#{utilities.sendEmail('/form2/mail.xhtml')}" />

The sendEmail() method returns the index.xhtml page for the form to redirect to. The index page also has the list of all the forms and is where users arrive when they first get started with the app.

I'd like to display a message of success or failure when the user has submitted the email, or if the user got to the page through a link, then don't show anything. Would I use Seam page parameters to tell index.xhtml that it's received a message?

Your help is much appreciated. Thanks.

+3  A: 

You can do it with a page parameter, but the easiest way would be to just add a message via seams FacesMessages and display it in the index.xhtml file:

@In
private FacesMessages facesMessages;

[...]

facesMessages.add(Severity.INFO, "Mail sent");

index.xhtml:

<h:messages />

You can also take a look at Seam navigation to redirect your view and add messages from there.

Elmar Weber
Thanks, Elmar. That's exactly what I needed :)
Alex
Sorry. Didn't realize that by clicking the "checkmark" I can indicate the correct answer. Done :)
Alex