Why Does FacesContext.addMessage Accept a String?

Hello,
For the life of me I can't figure this one out; please let me know if my thinking is incorrect here.
FacesContext.addMessage accepts two arguments, a String and a FacesMessage instance. The FacesMessage instance makes sense; it encapsulates all information regarding a message to the user. Why it doesn't support I18N under the covers, I don't know. This is, however, very easy to fix.
What I don't understand is the String instance argument. What is it used for? Sure, if I happen to bind a UIComponent, which also happens to have an h:message attached to it, to a managed bean I can programmatically add messages to the UIComponent. So, why is there no UIComponent.addMessage? Why the call to UIComponent.getClientId?
Furthermore, from a dumb API user (that's me) perspective, FacesContext.addMessage( String, FacesMessage) together with <h:messages id='...'/> seems to imply that FacesContext.addMessage( "selectiveMessage", ...) will only display that message for <h:messages id='selectiveMessage'/>, and no other h:messages tags. Unfortunately, even using globalOnly there is no way to have two mutually exclusive sets of messages that are not attached to a UIComponent.
This would not even be an issue except for the rendering order of JSP interfering with the allegedly stateful nature of the JSF components. For example, I have a set of status messages to the user, displayed above a dataTable. If the dataTable is empty, I want to display a nice "Listing is empty" status message to user instead of an empty table. However, since the messages are on top of the dataTable in the JSP page, the message does not show up until after refresh. The quick solution was to put another set of messages specifically for the empty table message under the table where everybody (all the components at least) already knows the state of dataTable. Unfortunately, can't have two mutually exclusive sets of messages.
So, we now have a very complex solution of custom behavior hard-wired into an h:messages subclass to solve a very simple problem of not displaying an empty table.
The good news is, aside from a few very annoying but certainly not show-stopping issues like this JSF is proving to be as good as its hype.
Thanks, JSF team!
Tim

Actually, this is incorrect. You must have a direct reference to the component instance to access the clientId. Filling in a String value that matches the for="..." attribute in h:message does not work. Furthermore, since UIComponent.getClientId requires a FacesContext instance argument, you end up with something like this:
FacesContext.getCurrentInstance().addMessage(
 this.getComponent().getClientId(
  FacesContext.getCurrentInstance()
 new FacesMessage( "This is not I18N!")
V/s this:
this.getComponent().addMessage( "i18nKey");
I do agree that JSF needs some input to get better. Hence this post.
Tim

Similar Messages

  • Why does Safari still accept cookies, even when I put Block Cookies "Always"

    Why does Safari still accept cookies, even when I put Block Cookies "Always",? There are always a list of every website with cookies. Is that just a record of what could've been accepted or its a bogus feature that still accepts regardless of what feature is on?

    Apple has rolled over users since OS X 10.6.8 when this issue first appeared.
    If you want a browser that actually CARES about it's users, then install Firefox, it's the only one that does.

  • Why does iphoto not accept my phone number when filling out shipping info for buying cards??

    Im trying to generate some thank you cards in iphoto 11 and when paying for them, it wont accept my telephone number in the Primary number box, which is in the delivery contact bit in the shipping information box. The telephone number keeps going red and i cant get any further with ordering the thank you cards. I have been to Itunes to check my billing and payment information and im using the same telephone number so i cant see why it wnt do it?? Please help as these thank you cards are from my kids to grandparents and other family members and my wife is getting irate at me, because i havent done what should be a simple thing!!!!!
    Many thanks if you can help.

    Try going to the Apple store (store.apple.com) and re-entering it in your account there and be sure that one click ordering is turned on and try again
    Also I'v eseen reports that number of digits can cause this if you are in an area that uses a different number of digits - I believe that someone reported that they had to move one digit to another field to get it to work - you might search the fourms for that post
    LN

  • My Military web site requires a certificate. My certificate that is loaded on mycard reader is a .cer file , foxfire wants a pkcs12 file so I can't load my certificate in foxfire.Why does foxfire not accept my .cer ?

    When I try to go to web sight https://sscc-fe-03.med.navy.mil/EXCHANGE I get the message "this page requires a client certificate. I have a Activcard card reader hooked up to USB port with my security inserted. I try to import my certificate into foxfire and it will only accept a pkcs12 file and my certificate is a .cer file. All the checks I do on my card reader show it is working properly and my security card works fine when on work computer but at home I have this problem. How can I get foxfire to accept my .cer certificate when I try to import it or read it off my card reader?
    Thanks

    I am running Firefox 12.0. It is not able to import the p12 files which wasn't a problem on the older versions or IE. The error message is either:
    PKCS#12 operation failed for unknown reasons
    or
    Failed to decode the file. Either it is not in PKCS#12 format, has been corrupted, or the password you entered was incorrect
    The p12 file I am using is from a certificate test suite from the department of defense. and the file works fine on IE.

  • Why does iPhoto say accept, why does iphot say accept

    when i try to download iphoto ( wich was already pre installed when i bought my macpro) it says "These apps cannot be accepted on this computer." HELP ME PLEASE!!!!!! thanks

    If you already had a previous version of iPhoto from either iLife '09 or iLife '11 on your Mac, then the upgrade to the current 64 bit version for OS X Mavericks is free.
    If you had no version of iPhoto or a earlier version of iPhoto installed on your Mac, then the current price would've appeared in the purchase button and you would've been charged $14.99 for the upgrade.

  • Why does mac not accept blank dvd

    My mac book pro keeps ejecting balnk dvd. even when accepted icon for dvd not showing on desktop.
    please help

    What do you have your preferences set for under System Preferences>CDs & DVDs?
    Here are mine:
    I have mine set to Open Finder when I insert a blank DVD because I mainly use DVDs to make backups. This way I can just drag files and folders to the DVD and burn them as a data DVD.
    How are your preferences set?
    Clinton

  • HT4623 Why does the update ask for a pass code? Previous updates did not.  Why does it NOT accept the only PIN I have set on this computer? Thanks.

    What the heck is a "pass code" and why am I being asked for one??  And where would I find said pass code?  I've not had to do that for prior updates, so am more than a bit confuzzed.  Thanks.

    The Passcode is the 4 digit code you use to unlock your iPad.

  • Why does adobe not accept my serial Number from Elements 3.

    can't install elements 3

    Welcome to the forum.
    As has been pointed out, you are referring to Photoshop Elements. There are enough differences between the Elements versions, and Photoshop (Ps Elements' "big brother"), that it will be best to Move your post to the very active and helpful Photoshop Elements Forum. Your link, and any e-mail subscriptions will follow.
    Good luck,
    Hunt
    [Moved to Photoshop Elements Forum]

  • Why does it not accept my card?

    My Apple ID automatically logged out and said there is a billing problem with my previous purchase when I have money in my account so I tried to change my payment method with two separate cards and neither worked it came up with the message your payment method is not available in this store. Please enter a new payment. All the information has been entered correctly and the cards are definitely valid one us a credit card and one is a debit card I have no idea what to do and it's frustrating because I cannot download or update anything. :( :(
    Please help me :(

    http://www.apple.com/support/itunes/contact/

  • Why does PL/SQL not support 0 length strings?

    Why does Trim(' ') return null instead of an empty string?
    Why does '' return null instead of an empty string?
    Because of this, LENGTH(Trim(' ')) returns null. And I want zero.
    I ask because I'm cutting up a string and in other languages (even ones that support Null) when these techniques are used, I get a valid empty string.
    Am I wrong in feeling that an empty string is the equivilent to a 0 in a numeric field and that null in a string is equivilent to null in a numeric field?
    Andy

    For Oracle, by definition, a null string is a string of length 0 since at least Oracle 5.0 (i do not know the previous ones).
    use NVL
    Why does Trim(' ') return null instead of an empty string?
    Why does '' return null instead of an empty string?
    Because of this, LENGTH(Trim(' ')) returns null. And I want zero.
    I ask because I'm cutting up a string and in other languages (even ones that support Null) when these techniques are used, I get a valid empty string.
    Am I wrong in feeling that an empty string is the equivilent to a 0 in a numeric field and that null in a string is equivilent to null in a numeric field?
    Andy

  • The ipad won't sync some photos, saying the file can't be read by the ipad, however it will sync some photos taken at the same time which are the same size and file type.  Why does it reject some and accept others?

    The ipad won't sync some photos, saying the file can't be read by the ipad, however it will sync some photos taken at the same time which are the same size and file type.  Why does it reject some and accept others?

    Hi there. I'm having the same problem: my iPad won't import some photos from a folder, saying that they can't be read. They are all JPEGS and some photos taken at the same time have synched fine, but out of a folder with 200 photos, it only lets me synch 37. I'm synching albums created via Photoshop Elements 6, which has worked fine until now.
    I've tried deleting all photos and re-synching, and have also deleted the iPod Photo Cache, but it hasn't made a difference.
    The iPad auto-updated to the latest version of iTunes, so maybe that's what's causing it?
    Any advice gratefully received!

  • Why does the apps store not accept my ID and password, it works fine to log into this forum and it works for the apple store, but not to log in to buy apps, it just keeps telling me that the id or password is wrong, and I know it isn't

    Why does the apps store not accept my ID and password, it works fine to log into this forum and it works for the apple store, but not to log in to buy apps, it just keeps telling me that the id or password is wrong, and I know it isn't

    I Just signed in to find the answer to this too.  I started having the same trouble today.

  • Why does Firefox remove the URL from the query string?

    Hello there,
    I've writing a servlet to read data from a file stored on a server. I'm using an HTTP <INPUT TYPE=file > element to locate the file to be read. When I run the servlet using IE as the browser it works fine. When I try running it using Firefox, the path to the file is not included in the query string. The full URL to the file shows up in the file input text field but then mysteriously disappears from the query string. Without the path, the servlet can't locate the file and the servlet fails. How do I get Firefox to include the path in the query string or is there some other workaround for this problem. I want my servlet to work on all types of browsers.
    thanks,
    grant

    Well you may also ask it the other way. Why does Microsoft send the full path file with the input type="file" component?
    The purpose of this control is to upload a file from the client to the server. That file is sent with the request.
    It does not allow you to browse server files at all. Most probably you are working on your developer machine where the client IS the server, so it works right now.
    It won't once they're seperate.
    <input type="file"> is the wrong tool to use to browser the server. You need to write your own html pages to do that.
    Cheers,
    evnafets

  • Why does apple app store doesnot accept  my debit card?

    why does apple app store doesnot accept  my debit card?

    iTunes Store Support
    http://www.apple.com/emea/support/itunes/contact.html
    Could be anything from a chargeback, or your card is junk depending on what it is. Using the word debit card isn't realy descriptive, and can many mean many, many different things.

  • Why does iTunes/iPhone 4S insist it can't find a song on my PC or my phone when it is on both? This is resulting in me being unable to use the ringtones I created from these songs, but I can still play the songs.

    OK, so I'm clearly a newb. I thought if I asked a question, it would post, and now I'm being told to post a comment, so I'm asking the same question again. Sorry I sound like an idiot. I'm new to this apple/mac stuff.
    Why does iTunes/iPhone 4S insist it can't find a song on my PC or my phone when it is on both? This is resulting in me being unable to use the ringtones I created from these songs, but I can still play the songs.

    If you have added the ringtone file correctly to iTunes, it will appear under iTunes 'Tones' library.
    If you don't find Tones library in iTunes, go to iTunes menu EDIT/PRFERENCES under GENERAL tab, check the Tones Box under Library source to display Tones library in iTunes.
    iTunes accepts only m4r file as ringtone and has to be less than 40secs.

Maybe you are looking for