|
|
Hi!
In a previous application I have been using a viewhandler to fetch all the messages written to the Faces Context, running through them and replacing the summary text with an index.
This way the error messages are presented with a number and the actual detailed message.
The previous application used JSF, tiles and Shale dialog.
I my new application I started using Spring Web Flow and the Spring MVC. While trying to use the same message handling in the new application nothing seems to happen.
It seems that FacesContext.getMessages() now is implemented by SWF, which returns FacesMessages, but only copies of them. The real messages are hold by the SWF framework. So when I make changes to the FacesMessages, it does'nt affect what is then viewed on the page.
(By looking at html/api/org/s...gate.java.html)
The setup of the view handler is as follows
Code:
lt;applicationgt;
lt;view-handlergt;com.sun.facelets.FaceletViewHandlerlt;/view-handlergt; lt;view-handlergt;myapp.viewhandler.ErrorViewHandler lt;/view-handlergt;
lt;/applicationgt;
And the actual implementation of the rewriting something like this:
Code: public void renderView(FacesContext context, UIViewRoot viewToRender)throws IOException, FacesException { Iteratorlt;FacesMessagegt; msgs = context.getMessages(); FacesMessage msg; int index = 0; while(msgs.hasNext()){msg = (FacesMessage) msgs.next();msg.setDetail(msg.getDetail());msg.setSummary(quot;(quot;+ ++index + quot;) quot; ); } handler.renderView(context, viewToRender);
}
Does anyone know how I could achieve this again?
I think I've seen a bug report on this before while googling, but I can't seem to find it again.
I found the bug report on
browse/SWF-1017
It turns out that this got fixed. After upgrading from SWF 2.0.5 to 2.0.8 I don't have the problem anymore.
Hm, but that didn't help me the whole way. It works for messages created by JSF validators, for which the original FacesMessage is the one returned by FacesContext.getMessages(). So when changing the summary for that kind of messages it will also be shown when rendering the page.
But messages created with the MessageBuilder have no backing FacesMessage instance. So it produces new instances of FacesMessages with every call to FacesContext.getMessages(). So any changes done to the messages like I described above will be lost.
Is there another way to achieve what I want? I rephrase it:
I want to present all error messages on the top of the page, with an index of the error and the detailed message.
Next to each element that yields an error I want to present the index of that error.
Does somebody know how to achieve this?
To get around the problem I'm adding messages as FacesMessages through the FlowFacesContextMessageDelegate. That makes it possible to alter the messages later.
That means I'm skipping using the MessageBuilder. It works but it is not a beautiful solution. |
|