I made a NotificationHandler class, this class contains a static List.
To allow access to this list I made a SessionScopped bean with a getter returning this list.
My problem is the following :
I’m on page A, I put a notification in the list, page A is regenerated, the notification is being displayed.
Then I click on a link in page A sending me to page B.
In page B there is a constructor wich destroy the list.
However the JSF page display the notification BEFORE calling the constructor.
I end up on page B with a notification for page A
Notification handler:
package com.cog.util;
import java.util.ArrayList;
import java.util.List;
public class NotificationHandler {
private static List<Notification2> listeDeNotification = new ArrayList<Notification2>();
public static void flushNotification(){
listeDeNotification.clear();
}
public static void raiseNotification(NotificationColor color, String code){
listeDeNotification.add(new Notification2(color.toString(), code));
}
public static void raiseNotification(NotificationColor color, String code, String additionalMessage){
listeDeNotification.add(new Notification2(color.toString(), code, additionalMessage));
}
public static void addAdditionalMessage(String code, String additionalMessage){
for(Notification2 n : listeDeNotification){
if (n.getCode().equals(code)){
n.setAdditionalMessage(additionalMessage);
}
}
}
public static Integer getNotificationNumber(){
return listeDeNotification.size();
}
public static List<Notification2> getListeDeNotification(){
return listeDeNotification;
}
}
notificationPrinter.xhtml
<composite:interface>
<composite:attribute name="liste" />
<composite:attribute name="locale" />
</composite:interface>
<composite:implementation>
<ui:repeat value="#{cc.attrs.liste}" varStatus="status" var="l">
<h:panelGrid width="100%" columns="1">
<div id="alert" class="alert #{l.color}">
<button class="close" data-dismiss="alert" type="button">×</button>
<span class="rt">#{cc.attrs.locale[l.code]} #{l.additionalMessage}</span>
</div>
</h:panelGrid>
</ui:repeat>
</composite:implementation>
AccessorBean
package com.cog.web.beans.util;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import com.cog.util.Notification2;
import com.cog.util.NotificationHandler;
@ManagedBean(name = "notificationAccessor")
@SessionScoped
public class NotificationAccessorBean {
public List<Notification2> getNotificationList(){
return NotificationHandler.getListeDeNotification();
}
}
and this is what I put in jsf
problem is I want to flush the notification list betwen some pages only.
Since you are using JSF you can use its advantages (
h:commandLink for example) , you can also might use thepreRenderViewtry placing it in your page and use itslistenerto flush the listtake a look at the following explanation/example JSF 2 PreRenderViewEvent example