-2

I am using Hibernate Validator with JSF, Richfaces. I have a text area wherein I input comma separated list of email domains.I have a hibernate ConstraintValidator which dutifully returns false if any of the email domains is not correct. In code elsewhere this constraint violation is captured & and an fatal error message is added to the FacesContext. But the error message is not displayed where I have the tag. Rather I get this in my console:

org.apache.myfaces.lifecycle.RenderResponseExecutor execute
WARNING: There are some unhandled FacesMessages, this means not every FacesMessage had a chance to be rendered.
These unhandled FacesMessages are: 
- Invalid Domain Name.

Versions: hibernate-validator-4.3.0.Final, myfaces-impl-2.2.12, richfaces-components-api-4.3.5.Final. In my project almost same code has been used in some other page, only the backing bean is different & there it displays FacesMessage in my facelet without problem. I have gone through the source code of org.apache.myfaces.lifecycle.RenderResponseExecutor:

List<FacesMessage> messageList = facesContext.getMessageList();
            if (!messageList.isEmpty())
            {
                StringBuilder builder = new StringBuilder();
                boolean shouldLog = false;
                for (int i = 0, size = messageList.size(); i < size; i++)
                {
                    FacesMessage message = messageList.get(i);
                    if (!message.isRendered())
                    {
                        builder.append("\n- ");
                        builder.append(message.getDetail());

                        shouldLog = true;
                    }
                }
                if (shouldLog)
                {
                    log.log(Level.WARNING, "There are some unhandled FacesMessages, " +
                            "this means not every FacesMessage had a chance to be rendered.\n" +
                            "These unhandled FacesMessages are: " + builder.toString());
                }
            }

If I view page source, I can see it is there:

<div class="error_block">
<span>Error </span> <br />
<table id="errorMessages"><tr><td class="displayErrorMessage">Invalid Domain Name.</td></tr></table>
</div></span>

But if I do F12 it is not there. So somehow the is not being part of DOM.

Subhendu Mahanta
  • 961
  • 1
  • 18
  • 44
  • PLEASE post the error you get in a searchengine of your liking and check the results... Errors/warnings are excelent search criteria – Kukeltje Apr 29 '18 at 07:15
  • I have done enough googling, read other answers in StackOverflow & went through source code of myfaces. – Subhendu Mahanta Apr 29 '18 at 07:24
  • That did not show in your Q.... In [ask] (which you should have read creating an account), it states to _"Search, and research ...and keep track of what you find. Even if you don't find a useful answer elsewhere on the site, including links to related questions that haven't helped can help others in understanding how your question is different from the rest. "_ And instead of posting **your** code in [mcve] flavour, you post MyFaces code. MyFaces usually is right, so the problem is with 99% certainty in your code. – Kukeltje Apr 29 '18 at 07:36
  • And _"In my project almost same code has been used in some other page, only the backing bean is different "_ **almost** being the relevant part... And are you sure the xhtml page is identical? – Kukeltje Apr 29 '18 at 07:38
  • I have posted MyFaces code because as I go debugging for the page which works as intended : List messageList = facesContext.getMessageList(); The messageList is empty, whereas the page where it does not work as intended, the messageList is not empty. – Subhendu Mahanta Apr 29 '18 at 07:56
  • So if you don't have a message then you don't get a warning and if you do have a message then you do get a warning... Al to be expected and reasons/solutions can all be found in lots of links in the internet.... A missing `h:message(s)` or a redirect without putting the message in flash scope... Lots of info on all this. – Kukeltje Apr 29 '18 at 08:33
  • Any progress??? – Kukeltje Apr 30 '18 at 18:02
  • @Kukeltje Thanks for asking.In faces-config.xml the navigation rule is having . I added this to code: context.getExternalContext().getFlash().setKeepMessages(true);No improvement.Thinking of 2 alternatives: remove all complexity from code i.e. remove custom components & make it as simple as possible. Other alternative is to copy the email domains textarea control from the page where it works & see if that also faces same problem. – Subhendu Mahanta May 02 '18 at 07:13
  • @Kukltje. I have edited the question to add page source.The error message is there in page source, but not in DOM tree. – Subhendu Mahanta May 03 '18 at 05:56

1 Answers1

0

As my updated question shows that if I view the source I can see the error message, but if I do 'Inspect Element' in Chrome the message is not there, that means it is not part of DOM. When creating the FacesMessage I have added the following:

context.addMessage(null, message);
context.getPartialViewContext().getRenderIds().add("globalMessage");

And in I used the id "globalMessage". Now the FacesMessage is being rendered.

Subhendu Mahanta
  • 961
  • 1
  • 18
  • 44