This content has been marked as final.
Show 1 reply
-
1. Re: Application error into h:messages
lvdberg Aug 19, 2010 1:03 PM (in response to chicco0386)Hi,
You can do that vut it means you have to capture you error before Seam does. Meaning you must do that in the bean where the error is produced. However you must reRender your page partially to visualise the error.
I am doing this with the help of an observer-bean which gets triggered from an error event, the bean receives the error an produces the trigger for a ajax-push which in turn rerenders a grwwl, which is a nice tag from the Primefaces library. All a bit complex, but it works.
Leo
@Name("incidentMessagePushBean") @Scope(ScopeType.APPLICATION) public class IncidentMessagePushBean { @In(required=false) FacesMessages facesMessages; @In(required=false) protected User currentUser; @Logger Log log; protected HashMap<String,PushEventListener> listeners = new HashMap<String, PushEventListener>(); protected HashMap<String, LinkedList<FacesMessage>> operatorMessages = new HashMap<String, LinkedList<FacesMessage>>(); @In(required=false) private Map<String, String> messages; public void addListener(EventListener l) { synchronized(this){ listeners.put(currentUser.getUserName(), (PushEventListener) l); } log.info("Added a listener for user " + currentUser.getUserName() + " we now have " + listeners.size() + " listeners." ); } /** This method catsches all the defined events and sends an update * request to all the views. Its minimum delay time is 5 seconds to ensure that * the display stays relatively stable. */ @Observer(value={"es.esam.im4u.incidentmessage.new", "es.esam.im4u.operator.login"} ) public synchronized void processEvent(String o, String h, String d){ FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_WARN, messages.get(h), messages.get(d)); /** Check if this message if directed to all users at-once */ if (o != null && o.equalsIgnoreCase("all")){ Set<String> keys = operatorMessages.keySet(); for (String name: keys){ if (operatorMessages.get(name).size() < 8) operatorMessages.get(name).add(msg); else { LinkedList<FacesMessage> list = operatorMessages.get(name); if(!list.isEmpty()) list.removeFirst(); operatorMessages.get(name).add(msg); } } } else { if (operatorMessages.get(o) == null ){ LinkedList<FacesMessage> list = new LinkedList<FacesMessage>(); list.add(msg); operatorMessages.put(o, list); } else { if (operatorMessages.get(o).size() < 8) operatorMessages.get(o).add(msg); else{ LinkedList<FacesMessage> list = operatorMessages.get(o); if(!list.isEmpty()) list.removeFirst(); operatorMessages.get(o).add(msg); } } } } /** Provides a value which will be used to give a message to the current user */ public void growl(){ if (currentUser != null && operatorMessages.get(currentUser.getUserName()) != null && operatorMessages.get(currentUser.getUserName()).size() > 0 ){ FacesContext context = FacesContext.getCurrentInstance(); for (FacesMessage m: operatorMessages.get(currentUser.getUserName())) { m.setSummary(messages.get(m.getSummary())); m.setDetail(messages.get(m.getDetail())); context.addMessage("test", m); } operatorMessages.get(currentUser.getUserName()).clear(); } } }