-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MYFACES-4612: FacesMessages don't store in different collections #593
Conversation
impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java
Show resolved
Hide resolved
I have to make one more fix. |
So Mojarra wrote a custom iterator so it could properly handle this scenario for iterating and removal. // ---------------------------------------------------------- Inner Classes
private static final class ComponentMessagesIterator implements Iterator<FacesMessage> {
private Map<String, List<FacesMessage>> messages;
private int outerIndex = -1;
private int messagesSize;
private Iterator<FacesMessage> inner;
private Iterator<String> keys;
// ------------------------------------------------------- Constructors
ComponentMessagesIterator(Map<String, List<FacesMessage>> messages) {
this.messages = messages;
messagesSize = messages.size();
keys = messages.keySet().iterator();
}
// ---------------------------------------------- Methods from Iterator
@Override
public boolean hasNext() {
if (outerIndex == -1) {
// pop our first List, if any;
outerIndex++;
inner = messages.get(keys.next()).iterator();
}
while (!inner.hasNext()) {
outerIndex++;
if (outerIndex < messagesSize) {
inner = messages.get(keys.next()).iterator();
} else {
return false;
}
}
return inner.hasNext();
}
@Override
public FacesMessage next() {
if (outerIndex >= messagesSize) {
throw new NoSuchElementException();
}
if (inner != null && inner.hasNext()) {
return inner.next();
} else {
// call this.hasNext() to properly initialize/position 'inner'
if (!hasNext()) {
throw new NoSuchElementException();
} else {
return inner.next();
}
}
}
@Override
public void remove() {
if (outerIndex == -1) {
throw new IllegalStateException();
}
inner.remove();
}
} // END ComponentMessagesIterator |
Is remove even supported by Specs? |
On the Iterator versions of getMessages I believe it is but on the List implementions of the return you are right its an unmodifiable List. How can we ask? Should I open a question on the Faces API GitHub? |
Try to check the javadocs and specs |
As far as I can see section 6.1.6 Message Queue deals with messages but it just mentions returning Iterators but not whether messages can be removed from the iterator at any phase? 6.1.6. Message Queue
During the Apply Request Values, Process Validations, Update Model Values, and Invoke Application public Interator<String> getClientIdsWithMessages();
public Severity getMaximumSeverity();
public Iterator<FacesMessage> getMessages(String clientId);
public Iterator<FacesMessage> getMessages(); The |
if this PR fixes the .remove case -> +1 |
{ | ||
return Collections.unmodifiableList(Collections.emptyList()); | ||
return Collections.emptyList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Collections.emptyList() returns an unmodifiable list by default
OK I fixed it now and updated the PR to handle the scenario of removal and using 1 collection to iterate. |
Because its a LinkedHashMap and the Lists they will remain ordered but not in separate storage containers.