You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Michael Heinen <mh...@recommind.com> on 2006/08/28 11:58:13 UTC

output text depending on message

Hi all,

 

I have to output some text in the case that there isn't a message for a
component.

How can I achieve this?

 

<t:inputText id="aField">...

<t:message for ="aField" showDetail ...>

 

<t:outputText value="ok" rendered=??? aField ???

 

I remember that this has been discussed here but I can't find it
anymore.

 

Michael


Re: output text depending on message

Posted by Mike Kienenberger <mk...@gmail.com>.
Turned out to be harder than I expected to find it :-)

http://issues.apache.org/jira/browse/TOMAHAWK-165


On 9/19/06, Mike Kienenberger <mk...@gmail.com> wrote:
> I vaguely recall someone submitting a new component for IfMessage
> -type stuff.   Search the jira issue tracker for New Component.
>
> On 8/28/06, Michael Heinen <mh...@recommind.com> wrote:
> > Thanks Volker for your help
> >
> > I can't use the approach with the isXXXError() method,
> > because my BackingBean contains a dynamic Map with attributes.
> > Therefore I can't hardcode getters for the attributes or the errors.
> >
> > So I try to implement such a MessagesWrapper by myself.
> > I create a new RequestScoped BackingBean that extends HashMap  and
> > overwrites the getter, right?
> >
> > public Object get(Object key) {
> >  String keyString = (String) key;
> >  return
> > FacesContext.getCurrentInstance().getMessages(keyString).hasNext();
> > }
> >
> > Thanks for putting me on this way.
> > Michael
> >
> > -----Original Message-----
> > From: Volker Weber [mailto:weber.volker@googlemail.com]
> > Sent: Montag, 28. August 2006 13:27
> > To: MyFaces Discussion
> > Subject: Re: output text depending on message
> >
> > Hi,
> >
> > > I hope there is a Map with messages, that would be accessible with the
> > fieldID????
> >
> > no, there isn't, but if you realy want you can implement such a map
> > yourselve.
> >
> > Or, as Gerald wrote, put a method like this in your backingBean
> >
> > public void isCarIdError() {
> > return FacesContext.getCurrentInstance().getMessages("carId").hasNext();
> > }
> >
> > that should do.
> >
> > Regards
> >   Volker
> >
> >
> >
> >
> >
>

Re: output text depending on message

Posted by Mike Kienenberger <mk...@gmail.com>.
I vaguely recall someone submitting a new component for IfMessage
-type stuff.   Search the jira issue tracker for New Component.

On 8/28/06, Michael Heinen <mh...@recommind.com> wrote:
> Thanks Volker for your help
>
> I can't use the approach with the isXXXError() method,
> because my BackingBean contains a dynamic Map with attributes.
> Therefore I can't hardcode getters for the attributes or the errors.
>
> So I try to implement such a MessagesWrapper by myself.
> I create a new RequestScoped BackingBean that extends HashMap  and
> overwrites the getter, right?
>
> public Object get(Object key) {
>  String keyString = (String) key;
>  return
> FacesContext.getCurrentInstance().getMessages(keyString).hasNext();
> }
>
> Thanks for putting me on this way.
> Michael
>
> -----Original Message-----
> From: Volker Weber [mailto:weber.volker@googlemail.com]
> Sent: Montag, 28. August 2006 13:27
> To: MyFaces Discussion
> Subject: Re: output text depending on message
>
> Hi,
>
> > I hope there is a Map with messages, that would be accessible with the
> fieldID????
>
> no, there isn't, but if you realy want you can implement such a map
> yourselve.
>
> Or, as Gerald wrote, put a method like this in your backingBean
>
> public void isCarIdError() {
> return FacesContext.getCurrentInstance().getMessages("carId").hasNext();
> }
>
> that should do.
>
> Regards
>   Volker
>
>
>
>
>

RE: output text depending on message

Posted by Michael Heinen <mh...@recommind.com>.
Thanks Volker for your help

I can't use the approach with the isXXXError() method,
because my BackingBean contains a dynamic Map with attributes.
Therefore I can't hardcode getters for the attributes or the errors.

So I try to implement such a MessagesWrapper by myself.
I create a new RequestScoped BackingBean that extends HashMap  and
overwrites the getter, right?

public Object get(Object key) {
 String keyString = (String) key;
 return
FacesContext.getCurrentInstance().getMessages(keyString).hasNext();
}

Thanks for putting me on this way.
Michael

-----Original Message-----
From: Volker Weber [mailto:weber.volker@googlemail.com] 
Sent: Montag, 28. August 2006 13:27
To: MyFaces Discussion
Subject: Re: output text depending on message

Hi,

> I hope there is a Map with messages, that would be accessible with the
fieldID????

no, there isn't, but if you realy want you can implement such a map
yourselve.

Or, as Gerald wrote, put a method like this in your backingBean

public void isCarIdError() {
return FacesContext.getCurrentInstance().getMessages("carId").hasNext();
}

that should do.

Regards
  Volker





Re: output text depending on message

Posted by Volker Weber <we...@googlemail.com>.
Hi,

> I hope there is a Map with messages, that would be accessible with the fieldID????

no, there isn't, but if you realy want you can implement such a map yourselve.

Or, as Gerald wrote, put a method like this in your backingBean

public void isCarIdError() {
return FacesContext.getCurrentInstance().getMessages("carId").hasNext();
}

that should do.

Regards
  Volker

RE: output text depending on message

Posted by Michael Heinen <mh...@recommind.com>.
Thanks, but this would not work in my case.
I have to check whether there are messages for specific fields.

Better sample:
I have a required editable inputField carID and want to output the name of the car if there are no errors for the carID field. If the carID field is changed then I clear the carName immediately via JS. When there is now a validation error for carID, then the old carName is displayed again.
I want to suppress the carName in errorCase.

<t:inputText id="carId" required="true" 
value="#{MyBean.attributes['carId']}"
onchange="document.getElementById('carname').innerText='')";/>

<t:message for="carId" showDetail...>

<t:outputText id="carName"
 value="#{MyBean.attributes['carName']}"
rendered=???empty messages['carId']???

I hope there is a Map with messages, that would be accessible with the fieldID????

Michael

-----Original Message-----
From: Gerald Müllan [mailto:bierbrauen@gmail.com] 
Sent: Montag, 28. August 2006 12:20
To: MyFaces Discussion
Subject: Re: output text depending on message

Hi,

what is about rendering the outputText in case if there are no
messages in the FacesContext waiting to be displayed:

FacesContext.getCurrentInstance().getMessages().hasNext()

Place this in a method-binding in the backend. Should work to me.

cheers,

Gerald

On 8/28/06, Michael Heinen <mh...@recommind.com> wrote:
>
>
>
>
> Hi all,
>
>
>
> I have to output some text in the case that there isn't a message for a
> component.
>
> How can I achieve this?
>
>
>
> <t:inputText id="aField">...
>
> <t:message for ="aField" showDetail ...>
>
>
>
> <t:outputText value="ok" rendered=??? aField ???
>
>
>
> I remember that this has been discussed here but I can't find it anymore.
>
>
>
> Michael


-- 
Gerald Müllan
Schelleingasse 2/11
1040 Vienna, Austria
0043 699 11772506
gerald.muellan@gmail.com





Re: output text depending on message

Posted by Gerald Müllan <bi...@gmail.com>.
Hi,

what is about rendering the outputText in case if there are no
messages in the FacesContext waiting to be displayed:

FacesContext.getCurrentInstance().getMessages().hasNext()

Place this in a method-binding in the backend. Should work to me.

cheers,

Gerald

On 8/28/06, Michael Heinen <mh...@recommind.com> wrote:
>
>
>
>
> Hi all,
>
>
>
> I have to output some text in the case that there isn't a message for a
> component.
>
> How can I achieve this?
>
>
>
> <t:inputText id="aField">…
>
> <t:message for ="aField" showDetail …>
>
>
>
> <t:outputText value="ok" rendered=??? aField ???
>
>
>
> I remember that this has been discussed here but I can't find it anymore.
>
>
>
> Michael


-- 
Gerald Müllan
Schelleingasse 2/11
1040 Vienna, Austria
0043 699 11772506
gerald.muellan@gmail.com