Jeff,

go ahead! would be great

the pattern Julian described (with the setErrorMessage() for instance)
is also used in shale's AbstractViewController/AbstractFacesBean ([1]).
The nice thing is that a Shale ViewController also addeds some
*lifecycle hook* methods, like init() or prerender.

-Matthias

[1] 
http://struts.apache.org/struts-shale/shale-core/apidocs/org/apache/shale/view/AbstractViewController.html

On 6/16/06, Jeff Bischoff <[EMAIL PROTECTED]> wrote:
Julian,

I like the methods you guys have for setting error messages. Seems that
some JSF books lack such relatively basic information (e.g. Core
JavaServer Faces)!

Since we have nothing in the Wiki about error reporting, perhaps it
would be useful to make such an entry. I could make a page describing a
stripped-down version of your methodology, unless you have the time to
make one yourself?

Regards,

Jeff Bischoff
Kenneth L Kurz & Assoc, Inc.

Julian Ray wrote:
> Here you go.
>
> We include this file in every page
>
> <%@ taglib uri="http://java.sun.com/jsf/html"; prefix="h"%>
> <%@ taglib uri="http://java.sun.com/jsf/core"; prefix="f"%>
> <%@ taglib uri="http://myfaces.apache.org/tomahawk"; prefix="t"%>
> <%@ taglib uri="http://c2glogistics.com/cms"; prefix="cms"%>
>
> <h:panelGrid styleClass="group" columns="2" cellpadding="2" cellspacing="0"
> width="100%" columnClasses="buttonCol, leftAlignCol"
> rowClasses="vertAlignTop" rendered="#{! empty facesContext.maximumSeverity}"
>
>       <h:graphicImage value="#{PageMessages.messageImage}" style="float:
> left; vertical-align: top;" />
>       <h:panelGrid columns="1" cellpadding="2" cellspacing="2"
> columnClasses="leftAlignCol" rowClasses="vertAlignTop" width="100%">
>           <h:outputText value="#{PageMessages.messageHeader}"
> escape="false" rendered="#{PageMessages.renderMessage}"/>
>           <h:messages errorClass="errorMessage" infoClass="infoMessage"
> layout="table" globalOnly="true" showDetail="false" showSummary="true"/>
>       </h:panelGrid>
> </h:panelGrid>
>
> It is backed up by a request-scoped backing bean which knows how to place
> message-specific images into the page
>
> import javax.faces.application.FacesMessage;
> import javax.faces.application.FacesMessage.Severity;
>
> import org.apache.commons.lang.StringUtils;
>
> import cms.beans.Messages;
>
> public class PageMessages extends AbstractUIBean {
>       private static final long serialVersionUID = -6479897299239746841L;
>       private static final String BEAN_NAME =
> PageMessages.class.getName();
>     private String messageHeader;
>     private String messageImage;
>     private Severity severityLevel;
>
>     public PageMessages() {
>
>       messageHeader = null;
>
>         // See if there are messages queued for the page
>         severityLevel = getFacesContext().getMaximumSeverity();
>         if (null != severityLevel) {
>             getLogger().debug("Severity Level Trapped: level = '" +
> severityLevel.toString() + "'");
>             if (severityLevel.compareTo(FacesMessage.SEVERITY_ERROR) == 0) {
>                 messageHeader = Messages.getString("PAGE_MESSAGE_ERROR");
>                 messageImage = "resources/warning.gif";
>             } else if (severityLevel.compareTo(FacesMessage.SEVERITY_INFO)
> == 0) {
>                 messageHeader = null;
>                 messageImage = "resources/information.gif";
>             } else if (severityLevel.compareTo(FacesMessage.SEVERITY_WARN)
> == 0) {
>                 messageHeader = null;
>                 messageImage = "resources/warning.gif";
>             } else if (severityLevel.compareTo(FacesMessage.SEVERITY_FATAL)
> == 0) {
>                 messageHeader = Messages.getString("PAGE_FATAL_ERROR");
>                 messageImage = "resources/stop.gif";
>             }
>         } else {
>             getLogger().debug("Severity Level Trapped: level = 'null'");
>         }
>     }
>     public Boolean getRenderMessage() {
>       return new Boolean(StringUtils.isNotBlank(getMessageHeader()));
>     }
>     /*
>      * Local Methods
>      */
>     /*
>      * Overrides
>      */
>     public String getBeanName() {
>         return BEAN_NAME;
>     }
>
>     /*
>      * Actions
>      */
>     /*
>      * Listeners
>      */
>     /*
>      * Validators
>      */
>     /*
>      * Accessors
>      */
>     public String getMessageHeader() {
>         return messageHeader;
>     }
>     public String getMessageImage() {
>         return messageImage;
>     }
> }
>
>
> -----Original Message-----
> From: Aleksei Valikov [mailto:[EMAIL PROTECTED]
> Sent: Friday, May 26, 2006 6:19 AM
> To: MyFaces Discussion
> Subject: Re: Handling and displaying action errors
>
> Hi.
>
>
>>The action method bindings of the backing beans process the request
>>and can determine the next view through returning a navigation
>>control. Null re-displays the current view so you can set up logic
>>which goes
>>
>>If (someBusinessLogic()) {
>>      displayConfirmationMessage();
>>      return myNextView;
>>} else {
>>      displayErrorMessage();
>>      return null;
>>}
>>
>>We have a message area included on each JSP page which processes
>>actions and inform the user of processing outcomes by using the
>>Message interface and sending warnings, errors and info messages. Each
>>of our backing beans inherits the following
>>
>>    protected void setInfoMessage(String msg) {
>>        getFacesContext().addMessage(null, new
>>FacesMessage(FacesMessage.SEVERITY_INFO, msg, null));
>>    }
>>
>>    protected void setWarnMessage(String msg) {
>>        getFacesContext().addMessage(null, new
>>FacesMessage(FacesMessage.SEVERITY_WARN, msg, null));
>>    }
>>    protected void setErrorMessage(String msg) {
>>        getFacesContext().addMessage(null, new
>>FacesMessage(FacesMessage.SEVERITY_ERROR, msg, null));
>>    }
>
>
> Well, this looks fine. So you just queue a message for the null client id?
> How do you display messages for null within the mage? Could you please post
> the corresponding code for the message area?
>
> Thank you.
>
> Bye.
> /lexi
>
>
>





--
Matthias Wessendorf
Aechterhoek 18
48282 Emsdetten
blog: http://jroller.com/page/mwessendorf
mail: mwessendorf-at-gmail-dot-com

Reply via email to