2011-12-07 221 views

回答

5

您可以用PhaseListener挂钩PhaseId.RENDER_RESPONSEbeforePhase()

例如

public class MessagesListener implements PhaseListener { 

    @Override 
    public PhaseId getPhaseId() { 
     return PhaseId.RENDER_RESPONSE; 
    } 

    @Override 
    public void beforePhase(PhaseEvent event) { 
     Iterator<FacesMessage> messageIterator = event.getFacesContext().getMessages(); 

     while (messageIterator.hasNext()) { 
      FacesMessage message = messageIterator.next(); 
      // ... 
     } 
    } 

    @Override 
    public void afterPhase(PhaseEvent event) { 
     // NOOP. 
    } 

} 

让它运行,如faces-config.xml如下注册它:

<lifecycle> 
    <phase-listener>com.example.MessagesListener</phase-listener> 
</lifecycle> 
+0

谢谢BalusC。它帮助了很多。 –

+0

不客气。 – BalusC