FYI: The general concepts are explained on pp. 211 - 213 of Core
JavaServer Faces.  It allows you to specify the id of the component for
which the message applies.

- Brendan

-----Original Message-----
From: Mike Kienenberger [mailto:[EMAIL PROTECTED] 
Sent: Friday, September 09, 2005 10:21 AM
To: MyFaces Discussion
Subject: Re: How to setup and display non-error messages


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(facesC
ontext),
                    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"/>

On 9/9/05, Rick Reumann <[EMAIL PROTECTED]> wrote:
> Mike, could you explain more the concept of the
> "optionalRelatedComponentReference" - what would be an example of its
> usage? Since I'm new, I haven't run across using the
> ComponentReference.getClientId construct yet.
> 
> (note: gmail might be adding my gmail address as the reply-to address
> instead of the list, and I have no idea why - so if someone replies to
> this make sure it has the list address. Anyone else besides Mike and I
> noticing gmail doing this?)
> 
> On 9/9/05, Mike Kienenberger <[EMAIL PROTECTED]> wrote:
> > <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.
> >
> >
> > On 9/9/05, Rick Reumann <[EMAIL PROTECTED]> wrote:
> > > I'm looking in the section of Core JSF on "messages" but I don't
see
> > > how to create a typical "Your update of John Doe was Successful"
type
> > > of message to be used on a JSP.
> > >
> > > How do you accomplish this with JSF/MyFaces?
> > >
> > > It seems like h:message and h:messages is really only geard for
error
> > > type messages, but what about standard success type message?
> > >
> > > Actually, I don't even see how to set up error messages. For
example
> > > if I make a call to some backend procedure and want to display a
> > > failure message, how do I do this?
> > >
> > > TIA,
> > >
> > > --
> > > Rick
> > >
> >
> 
> 
> --
> Rick
>

Reply via email to