You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Mark Li <xi...@gmail.com> on 2010/06/13 07:11:03 UTC
How can I notice if there are facesmessages via ajax
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
Re: How can I notice if there are facesmessages via ajax
Posted by 李析寒 <xh...@northking.net>.
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
>
>
>
>
Re: How can I notice if there are facesmessages via ajax
Posted by "Luca Graf (Inxmail GmbH)" <lu...@inxmail.de>.
I use this approach to decide if an dialog should be closed or keeped
open (to show validation errors).
form that holds the max Severity:
<h:form id="severityForm" style="display:none;">
<h:inputHidden id="maximumSeverity"
value="#{facesContext.maximumSeverity.ordinal}"/>
</h:form>
In my js callbacks i use this function to decide:
function requestContainsErrors()
{
return document.getElementById('severityForm:maximumSeverity').value
>= '2';
}
Its a bit complicated because you must rerender the hidden field on ajax
requests too. If you use richfaces you can put the hidden field in an
<a4j:outputPanel> to avoid manual rerender.
This works but i agree there should be an convenient way to check for
error messages (or validation errors) in the js callbacks.
Regards,
Luca
Jakob Korherr wrote:
> Hi Mark and Werner,
>
> You could also add a h:messages component to the page and re-render this one
> in any ajax-request. If the dom-update for this component is not empty, then
> you know that there are FacesMessages.
>
> Regards,
> Jakob
>
> 2010/6/13 Werner Punz <we...@gmail.com>
>
>
>> Am 13.06.10 07:11, schrieb Mark Li:
>>
>> 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?
>>>
>>> Hi there is no direct handling of faces-messages in the protocol, if you
>>>
>> do a standard ajax request you will get something back like
>> <update id="bbb">html code to update </update>
>>
>> so what you can do is to check the response for updated message fields.
>> The protocol unfortunately does not deal with messages directly all it does
>> is to deal with dom nodes which get updated.
>>
>> The protocol allows following tags but only update is used due to a spec
>> limitation which hopefully will be lifted on 2.1
>> (on component level)
>>
>> <update>
>> <insert>
>> <delete>
>> <attributes>
>> <eval>
>> <extension> afair with extension being a place for specific extensions.
>>
>> So currently both impls do not use extension but if you need direct access
>> to the faces messages you could add a custom mechanism (responsewriter,
>> maybe an event handler ), which drags them directly in and use the
>> extensions tag for this purpose, but then you have to parse them out also
>> via an event handler.
>>
>>
>> Werner
>>
>>
>>
>
>
>
--
Technical Consulting
------------------------------------------------------
Inxmail GmbH
Wentzingerstr. 17, 79106 Freiburg, Germany
Tel: +49 761 296979-404, Fax: -9
luca.graf@inxmail.de, www.inxmail.de
Handelsregister Freiburg, HRB 5870
USt.-ID: DE198371679
Geschäftsleitung: Martin Bucher, Peter Ziras
------------------------------------------------------
Inxmail Professional kostenlos testen:
http://www.inxmail.de/jetzt-testen
Tipps und Tricks für E-Mail-Marketers:
http://www.inxmail.de/newsletter
Inxmail kompakt in 140 Zeichen:
http://www.twitter.com/inxmail_gmbh
Re: How can I notice if there are facesmessages via ajax
Posted by Werner Punz <we...@gmail.com>.
Thats basically solution 1 I proposed, but somewhat easier then to check
the entire response :-)
Werner
Am 14.06.10 13:31, schrieb Jakob Korherr:
> Hi Mark and Werner,
>
> You could also add a h:messages component to the page and re-render this one
> in any ajax-request. If the dom-update for this component is not empty, then
> you know that there are FacesMessages.
>
> Regards,
> Jakob
>
> 2010/6/13 Werner Punz<we...@gmail.com>
>
>> Am 13.06.10 07:11, schrieb Mark Li:
>>
>> 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?
>>>
>>> Hi there is no direct handling of faces-messages in the protocol, if you
>> do a standard ajax request you will get something back like
>> <update id="bbb">html code to update</update>
>>
>> so what you can do is to check the response for updated message fields.
>> The protocol unfortunately does not deal with messages directly all it does
>> is to deal with dom nodes which get updated.
>>
>> The protocol allows following tags but only update is used due to a spec
>> limitation which hopefully will be lifted on 2.1
>> (on component level)
>>
>> <update>
>> <insert>
>> <delete>
>> <attributes>
>> <eval>
>> <extension> afair with extension being a place for specific extensions.
>>
>> So currently both impls do not use extension but if you need direct access
>> to the faces messages you could add a custom mechanism (responsewriter,
>> maybe an event handler ), which drags them directly in and use the
>> extensions tag for this purpose, but then you have to parse them out also
>> via an event handler.
>>
>>
>> Werner
>>
>>
>
>
Re: How can I notice if there are facesmessages via ajax
Posted by Jakob Korherr <ja...@gmail.com>.
Hi Mark and Werner,
You could also add a h:messages component to the page and re-render this one
in any ajax-request. If the dom-update for this component is not empty, then
you know that there are FacesMessages.
Regards,
Jakob
2010/6/13 Werner Punz <we...@gmail.com>
> Am 13.06.10 07:11, schrieb Mark Li:
>
> 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?
>>
>> Hi there is no direct handling of faces-messages in the protocol, if you
> do a standard ajax request you will get something back like
> <update id="bbb">html code to update </update>
>
> so what you can do is to check the response for updated message fields.
> The protocol unfortunately does not deal with messages directly all it does
> is to deal with dom nodes which get updated.
>
> The protocol allows following tags but only update is used due to a spec
> limitation which hopefully will be lifted on 2.1
> (on component level)
>
> <update>
> <insert>
> <delete>
> <attributes>
> <eval>
> <extension> afair with extension being a place for specific extensions.
>
> So currently both impls do not use extension but if you need direct access
> to the faces messages you could add a custom mechanism (responsewriter,
> maybe an event handler ), which drags them directly in and use the
> extensions tag for this purpose, but then you have to parse them out also
> via an event handler.
>
>
> Werner
>
>
--
Jakob Korherr
blog: http://www.jakobk.com
twitter: http://twitter.com/jakobkorherr
work: http://www.irian.at
Re: How can I notice if there are facesmessages via ajax
Posted by Werner Punz <we...@gmail.com>.
Am 13.06.10 07:11, schrieb Mark Li:
> 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?
>
Hi there is no direct handling of faces-messages in the protocol, if you
do a standard ajax request you will get something back like
<update id="bbb">html code to update </update>
so what you can do is to check the response for updated message fields.
The protocol unfortunately does not deal with messages directly all it
does is to deal with dom nodes which get updated.
The protocol allows following tags but only update is used due to a spec
limitation which hopefully will be lifted on 2.1
(on component level)
<update>
<insert>
<delete>
<attributes>
<eval>
<extension> afair with extension being a place for specific extensions.
So currently both impls do not use extension but if you need direct
access to the faces messages you could add a custom mechanism
(responsewriter, maybe an event handler ), which drags them directly in
and use the extensions tag for this purpose, but then you have to parse
them out also via an event handler.
Werner