Closed GoogleCodeExporter closed 9 years ago
What if more messages were added during the second request? Then the original
messages may be destroyed.
Original comment by lincolnb...@gmail.com
on 10 Feb 2011 at 7:07
Yeah, thats correct. But is this a common situation? I think this is a
typically scenario:
* The user submits some form:
(1) If there are validation errors or the action method creates messages during a custom "in-code" validation, the page will be re-rendered in the same request (action returns null).
(2) If everything works fine the action will queue a "Success" message and redirect to another PrettyFaces mapping.
I think this is the most common case. At least in my apps! :-)
Unfortunately (1) doesn't work in MyFaces apps so I think we should find a way
to fix this.
What about checking if there is already "the same" message in the context
before adding one? It looks like the FacesMessage class doesn't implement
equals()/hashcode() so we would have to do this manually by comparing all
relevant properties.
Original comment by chkalt
on 11 Feb 2011 at 6:53
Yeah I think that comparing properties is probably the way to go - I don't
think *anyone* wants duplicate messages showing up anyway. We'll need to
compare severity, message, and details I think. Since we don't support
re-attaching to components, we don't need to worry about that.
Original comment by lincolnb...@gmail.com
on 11 Feb 2011 at 3:29
Sounds good. Let's to it this way. :-)
Original comment by chkalt
on 13 Feb 2011 at 2:50
Hey Lincoln,
I just finished to implement correct "duplicated messages" handling in
FacesMessageUtils. Here is what I did:
1. I created a class called FacesMessageWrapper which wraps a FacesMessage and
implements hashcode()/equals() correctly.
2. I replaced all "ArrayList<FacesMessage>" with
"LinkedHashSet<FacesMessageWrapper>" (including the list stored in the session).
3. In restoreMessages() only the messages not already in the FacesContext are
restored.
4. saveMessages() doesn't remove the FacesMessages from the FacesContext
anymore. I think we don't need this and it is dangerous to do this, because we
don't know for sure if the JSF implementation returns an Iterator that allows
to call remove().
The code is currently on a separate branch:
https://github.com/chkal/prettyfaces/tree/messagefix
What do you think? I think this should finally fix the issues with MyFaces. I
did some quick tests with MyFaces and Mojarra and everything worked fine. I'll
try to test the new code on one of our current projects tomorrow. If I find no
issues I would like to merge it into the master branch so that we can include
it in 3.2.1.
Original comment by chkalt
on 28 Feb 2011 at 4:29
Merged and pushed to the master repository
Original comment by chkalt
on 9 Mar 2011 at 7:03
Original issue reported on code.google.com by
chkalt
on 10 Feb 2011 at 4:28Attachments: