Hi Mark this would be a good idea to post the problem in issue tracker
for the spec, so that it might be covered in a future revision.
Btw. a cleaner solution probably would be to write your own partial
response writer on top of the existing one which adds the info regarding
the messages (or embed it in the extends part which is used for extensions)
The ResponseWriter is delivered from the FacesContext, which has a clear
extension point to get it in.
I would not hack it into the impl, I´d rather use one of the extension
points that way you can ensure that it works over myfaces and mojarra.
Werner
Am 23.06.10 10:01, schrieb Mark Li:
Hi everyone,
1、to Werner, i hates it too, i dont like use update, its not a universal
solution.
2、to Jakob, h:messages is a solution, i used to use it. but when you want to
show some message dialog, you have to add things in very page, even in every
form. very ugly.
my solution is hack the sourcecode, hehe.
Java Side:
org.apache.myfaces.context.servlet.PartialViewContextImpl{
....
private void processPartialRendering(UIViewRoot viewRoot, PhaseId phaseId){
List<FacesMessage> messages = _facesContext.getMessageList();
Integer messageSize = 0;
StringBuffer sb = new StringBuffer();
if(messages != null){
messageSize = messages.size();
for(FacesMessage m : messages){
if(m.isRendered())
continue;
sb.append("<message
severity=\"").append(m.getSeverity().getOrdinal()).append("\"><![CDATA[").append(m.getSummary()).append("]]></message>");
m.rendered();
}
}
writer.append("<update id=\"javax.faces.MessageState\"
size=\"").append(messageSize.toString()).append("\">").append(sb).append("</update>");
}
...
}
also jsf.js
myfaces._impl.xhrCore._AjaxResponse.prototype.processUpdate{
...
}else if (node.getAttribute("id") == "javax.faces.MessageState") {
if(node.getAttribute("size") != "0"){
var m = [];
var mn = node.childNodes;
for(var i = 0 ; i< mn.length ; i ++ ){
if(mn[i].tagName == 'message'){
m[m.length]= {message:mn[i].textContent,
severity:mn[i].getAttribute("severity")};
}
}
request.responseMessages = m;
request.responseMessageSize = node.getAttribute("size");
}
} else {
var cDataBlock =
myfaces._impl._util._Utils.concatCDATABlocks(node);
....
}
myfaces._impl.core._jsfImpl.prototype.sendError {
......
eventData.source = context.source;
eventData.responseXML = request.responseXML;
eventData.responseText = request.responseText;
eventData.responseCode = request.status
eventData.responseMessages = request.responseMessages;
eventData.responseMessageSize = request.responseMessageSize;
...
}
myfaces._impl.core._jsfImpl.prototype.sendEvent{
eventData.responseXML = request.responseXML;
eventData.responseText = request.responseText;
eventData.responseCode = request.status
eventData.responseMessages = request.responseMessages;
eventData.responseMessageSize = request.responseMessageSize;
}
I think you will not like it, but its a final solution to me.
anyway, the specification should give a solution about delivery messages in
ajax via jsf.ajax.request.
Mark.
On Jun 13, 2010, at 1:11 PM, Mark Li wrote:
when i use jsf.ajax, i cant find out any information about facesmessage.
I have looked into "Event Object", but find nothing.
My situation is,
jsf.ajax.request(this, event,{
onerror:function(data){alert('nothing happened!')},
onevent:function(data){
//if there is message do something. will do like keep dialog.
//if there is no message do otherthings. will do like close dialog;
}
} );
Can anyone help?
thx
Best Regard
Mark Li
xihan...@gmail.com