Send email and display status using modalPanel
oneworld95 Jul 1, 2009 12:25 PMHi. I've got a Seam app that sends the data from a form to an email address. When the user clicks Submit, it displays any validation errors in a <rich:modalPanel>; otherwise, it sends the email.
I've been pulling my hair out trying to figure out how to display the status of the email ("Sending email...", "Email sent successfully.") in a modalPanel and haven't had any success.
Here's what I've got for the Submit button and the modalPanel that displays the validation errors:
<a4j:commandButton action="#{newemployee.sendEmail()}" value="Submit" oncomplete="#{facesContext.maximumSeverity == null ? 'Richfaces.hideModalPanel(\'mpErrors\');' : 'Richfaces.showModalPanel(\'mpErrors\');'}"/> <rich:modalPanel id="mpErrors" width="350" height="250"> <f:facet name="header"> <h:panelGroup> <h:graphicImage value="/img/msginfo.png" style="float:left; margin-right: 3px;" /> <h:outputText value="System Messages" /> </h:panelGroup> </f:facet> <f:facet name="controls"> <h:panelGroup> <h:graphicImage value="/img/close.png" styleClass="hidelink" id="hidelinkmpErrors"/> <rich:componentControl for="mpErrors" attachTo="hidelinkmpErrors" operation="hide" event="onclick"/> </h:panelGroup> </f:facet> <a4j:outputPanel ajaxRendered="true" style="width:100%"> <rich:messages passedLabel="Data is allowed to be emailed." style="width:100%; text-align: left; color: red; font-weight: bold;" rendered="#{facesContext.maximumSeverity == null ? 'false' : 'true'}" layout="list"> <f:facet name="errorMarker"> <h:graphicImage style="margin-right: 5px;" value="/img/msgerror.png" /> </f:facet> </rich:messages> <div style="text-align:center"> <a4j:commandButton style="text-align:center; margin: 29px;" id="btnReturn" value="Return to Form" > <rich:componentControl for="mpErrors" attachTo="btnReturn" operation="hide" event="onclick"/> </a4j:commandButton> </div> </a4j:outputPanel> </rich:modalPanel>
Here's the code for the sendEmail() method:
@In private Renderer renderer; public void sendEmail() { status = (this.isHasMessages()) ? "Validation errors occurred." : "Processing email now..."; try { renderer.render("/mail.xhtml"); status = "Email sent successfully."; } catch (javax.faces.FacesException e) { status = "An error occurred while sending the email: " + e.getMessage(); } }
How do I display the status of the email using the <a4j:status> in a modalPanel? Thanks.