myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Myfaces Wiki] Update of "Create and Display Messages" by RickReumann
Date Fri, 09 Sep 2005 15:33:14 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The following page has been changed by RickReumann:
http://wiki.apache.org/myfaces/Create_and_Display_Messages

New page:
'''From Mike Kienenberger, posted on MyFaces mailing list:'''

<h:messages globalOnly="true" showDetail="true"/>
<h:message for="<optionalRelatedComponentId>" showDetail="true"/>

FacesContext facesContext = FacesContext.getCurrentInstance();

facesContext.addMessage(<optionalRelatedComponentReference>.getClientId(facesContext),
                   new FacesMessage(FacesMessage.SEVERITY_<WHATEVER>,
                       "<messageSummary>", "<messageDetail>"));

optionalRelatedComponentReference.getClientId(facesContext) can be
replaced with null if you want a global message.

'''Mike's example of the above in use:'''

This is an example of how I've used it.  Note that I can change to any
kind of UIInput to represent an externalCustomerLastName, and my code
remains unchanged.  Probably not as useful for a last name field, but
for input components that might change between inputCalendars or
pulldowns or inputText fields, it's very helpful.

   private transient UIInput externalCustomerLastNameInput;
   public UIInput getExternalCustomerLastNameInput()
   {
       return this.externalCustomerLastNameInput;
   }
   public void setExternalCustomerLastNameInput(
           UIInput externalCustomerLastNameInput)
   {
       this.externalCustomerLastNameInput = externalCustomerLastNameInput;
   }

facesContext.addMessage(externalCustomerLastNameInput.getClientId(facesContext),
                   new FacesMessage(FacesMessage.SEVERITY_ERROR,
                       "Last name mismatch", "The last name doesn't
match the record found."));

<h:outputLabel for="ExternalCustomerLastNameInput">
   <h:outputText value="Customer Last Name:"/>
</h:outputLabel>
<h:inputText id="ExternalCustomerLastNameInput"
   binding="#{page.externalCustomerLastNameInput}"
   value="#{dataModel.externalCustomerLastName}"/>
<h:message for="ExternalCustomerLastNameInput" styleClass="errors"
showDetail="true"/>

Mime
View raw message