You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by Apache Wiki <wi...@apache.org> on 2005/09/09 17:33:14 UTC
[Myfaces Wiki] Update of "Create and Display Messages" by RickReumann
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"/>