myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Werner Punz <werner.p...@gmail.com>
Subject Re: How can I notice if there are facesmessages via ajax
Date Wed, 23 Jun 2010 21:06:02 GMT
Hi the facesContext has a method getPartialReponseWriter, or 
getResponseWriter is giving back the partial response writer.
By pushing your own FacesContext in (via the FacesContextFactory)
you can override this mechanism by wrapping the system partial response 
writer and adding your messaging functionality.

After all the components just use the response writer given by them to 
push in whatever they do. I do not think you have to doctor around the 
PartialViewContext to achieve the functionality.

Werner


Am 23.06.10 18:56, schrieb Mark Li:
> Hi Werner,
>
> Thank you for help. but  I don't really get your point about ResponseWriter extension.
>
> I looked around the code, and I only find out PartialReponseWriter object is instantiated
in the hard code. I
>
> like below,
>   org.apache.myfaces.context.servlet.PartialViewContextImpl{
> ...
>                  _partialResponseWriter = new PartialResponseWriterImpl(responseWriter);
> ...
> }
> .
> and this code in org.apache.myfaces.context.servlet.PartialViewContextImpl has used FacesContext.setResponseWriter
method to set PartialResponseWriter object. So can you explain your idea in more detail? thank
a lot.
>
> further,
>
> I have submit a new topic about "Ajax Error Handler problem", sorry for hacking the code
again.
>
> Mark
>
>
>
> On Jun 23, 2010, at 9:00 PM, Werner Punz wrote:
>
>> 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
>>>> xihanlee@gmail.com
>>>>
>>>>
>>>>
>>>>
>>>
>>
>>
>
>



Mime
View raw message