QeelwaEtech / omnifaces

Automatically exported from code.google.com/p/omnifaces
0 stars 1 forks source link

utils - Exceptions: manager to manage rendering of messages when page invokes multiple AJAX request, simultaneously #87

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
OmniFaces,

In response to the following on utils - Exceptions showcase page,

If you know more useful methods/functions which you think should be added to 
this OmniFaces utility class so that everyone can benefit from a "standard" JSF 
utility library, feel free to post a feature request.

I'd like to ask, is there some type of exceptions 'rendering' manager that can 
be added to OmniFaces utils - Exceptions?

Okay, here is my issue or my situation/implementation:

1. PrimeFaces Push has a showcase or use case called FacesMessages
2. Since I am using Glassfish, PrimeFaces Push does not work well with 
Glassfish, so I implemented my own version of "Push FacesMessages" (or 
'notifications') via p:poll (AJAX request).
3. Now, here's the issue, I believe, I believe that p:poll to 
checkForNotifications() is clashing with other AJAX and/or non-AJAX requests.
4. p:poll is added to the parent xhtml page
5. All child/children xhtml pages may contain commandLink/Button's and/or 
components with (PrimeFaces) p:ajax, which makes AJAX/non-AJAX requests, and 
for this reason, I believe/think that I am getting the following (MyFaces) 
exception (every now and then) in server log:

[#|2012-10-28T04:26:12.515-0400|WARNING|glassfish3.1.2|org.apache.myfaces.lifecy
cle.RenderResponseExecutor|_ThreadID=95;_ThreadName=Thread-2;|There are some 
unhandled FacesMessages, this means not every FacesMessage had a chance to be 
rendered.
These unhandled FacesMessages are: 
- ORDER updated: NOTES|#]

6. Yes, I searched google.com and stackoverflow.com for this exception, and I 
found the following:

http://stackoverflow.com/questions/8833768/displaying-an-error-message-for-an-er
ror-that-happens-in-a-getter-not-in-an-act

https://issues.jboss.org/browse/RF-11331

https://issues.apache.org/jira/browse/TRINIDAD-2227

7. This 'may' be a MyFaces issue, but I think my implementation of p:poll and 
other commandLink/Buttons/p:ajax is causing the issue, but I may be wrong.
8. I am quite sure that I am 'not' adding facesMessages in any getter methods, 
but p:poll listener="#{usersController.checkNotifications()}" update="growl" 
may be almost similar to a getter method; please correct me, if I am wrong.
9. Please note, recently I started using p:growl to render/display p:poll 
notifications (in a notifications form on parent xhtml page) AND I am using 
p:growl to render/display messages for child/children xhtml pages (in separate 
forms per child xhtml page). Even though I have started using p:growl on many 
child/children xhtml pages, one or two children xhtml pages may contain 
p:messages, so, I think MyFaces impl is getting confused if "a" facesmessage 
was actually rendered or not, OR, MyFaces may 'not' be rendering "a" 
facesmessage via p:messages, when p:poll just finished or interrupted another 
AJAX or non-AJAX request.
10. Also, please note, many of my navigation from page to page is 
p:commandButton/Link ajax="false", but the error message that I copy/pasted 
above is 'definitely' from a p:ajax. I usually see that same error and one 
other error message (below):

[#|2012-10-28T06:45:02.781-0400|WARNING|glassfish3.1.2|org.apache.myfaces.lifecy
cle.RenderResponseExecutor|_ThreadID=93;_ThreadName=Thread-2;|There are some 
unhandled FacesMessages, this means not every FacesMessage had a chance to be 
rendered.
These unhandled FacesMessages are: 
- MCT: 01/39 pricing includes Additional Driver Cost. Please move this cost to 
Meals, if applicable.|#]

11. The facesmessage above is definitely and 'only' supposed to be displayed 
in/via p:messages, and enduser will most likely see this when View 
commandButton/Link is clicked, either from the Browse page (which contains 
p:dataTable, to list data/rows), or from the Edit page, AND the View 
commandButton/Link is ALWAYS ajax="false".
12. This just reminded me, that I did read a BalusC answer on stackoverflow.com 
that commandButton/Link (POST) is not best for page-to-page navigation, but 
page-to-page navigation, in my app, is not by 'URL' or GET request, it is 
basically using ui:include src="#{pageNavigationController.page}", and this is 
working as designed and perfectly for me.

So, can a facesmessage-rendering-manager utility be developed for something 
like this implementation that I have in place, or do I need to add some type of 
Boolean to my UsersController (sessionscoped), and set that boolean = true, 
whenever commandLink/Button's and p:ajax, on child xhtml pages, are invoked, so 
p:poll will 'wait' to populate facesMessage from/via the following code in 
UsersController?

    public void checkNotifications() {
        List<String> list = applicationScopeBean.getNotifications(user);
        if (list != null && !list.isEmpty()) {
            for (String msg : list) {
                messages.addFormInfoMsg(msg, "");
            }
        }
    }

13. One last thing, please note, that I don't add process="..." to any 
p:ajax/etc... in my app, and I don't use f:ajax at all.

Original issue reported on code.google.com by smithh03...@gmail.com on 30 Oct 2012 at 9:03

GoogleCodeExporter commented 9 years ago
OR, please let me know if I should ask this question on stackoverflow.com as a 
regular question without the notion of an OmniFaces 'feature request'.

Original comment by smithh03...@gmail.com on 30 Oct 2012 at 9:06

GoogleCodeExporter commented 9 years ago
I just read the following:

http://stackoverflow.com/questions/9025782/how-to-display-a-facesmessage-for-a-c
ommand-link

I may need to follow those suggestions to solve this. :)

Original comment by smithh03...@gmail.com on 30 Oct 2012 at 9:22

GoogleCodeExporter commented 9 years ago
I added code in my UsersController.checkNotifications() for the p:poll to add 
clientId="pollNotificationsform:pollForNotifications), but server log returned 
the following:

INFO: pf_UsersController.checkNotifications(): Components.findComponent(...) 
found pollNotificationsForm:pollForNotifications
WARNING: There are some unhandled FacesMessages, this means not every 
FacesMessage had a chance to be rendered.
These unhandled FacesMessages are: 
...

So, I followed directions, specifically as Cagatay stated in forum topic below:

http://forum.primefaces.org/viewtopic.php?f=14&t=19179&p=62069&hilit=globalonly#
p62069

p:growl/messages for="..." and addMessage("...", new FacesMessage(...)) where 
"..." must match in xhtml and bean.

So, I 'think' I solved this issue by using this approach, and I went through 
and did the following:

1. added globalOnly="true" to the p:growl/messages in children xhtml pages for 
all the FacesMessages in my app where I do addMessage(null, new 
FacesMessages(...))

2. p:growl for="pollForNotifications" and addMessage("pollForNotifications", 
new FacesMessage(...)) on parent xhtml page

So, BalusC, you can mark this issue as Invalid, if you like. Thanks. :)

Original comment by smithh03...@gmail.com on 30 Oct 2012 at 11:27

GoogleCodeExporter commented 9 years ago
Indeed, the error "There are some unhandled FacesMessages, this means not every 
FacesMessage had a chance to be rendered." is after all a developer error.

Thank you for your effort though. In the future, if there's uncertainty, you'd 
indeed better open a topic on PF forum, or a question on SO.

Original comment by balusc on 31 Oct 2012 at 12:28

GoogleCodeExporter commented 9 years ago
Okay, thanks.

Original comment by smithh03...@gmail.com on 31 Oct 2012 at 12:29