Michael Heinen | 2 Feb 11:05

onsumit not exeucted for ajax requests - alternative?

Hi,

I am currently migrating an application to JSF 2.1

I have a lot of ajax commands (richfaces) and some new f:ajax tags.
My forms contain some js functions which should be called during 
onsubmit but unfortunately onsubmit is not called for ajax requests.

How can I specify some JS functions that should be executed before any 
ajax call?
I do not want to add them to a few hundred commands manually and would 
like to define the calls on a few spots as possible.

Thanks,
Michael

Milo van der Zee | 2 Feb 11:21
Favicon

Re: onsumit not exeucted for ajax requests - alternative?

Hello Michael,

might be that 'onbegin' does what you want?

MAG,
Milo van der Zee

On Thu, 2012-02-02 at 11:05 +0100, Michael Heinen wrote:
> Hi,
> 
> I am currently migrating an application to JSF 2.1
> 
> I have a lot of ajax commands (richfaces) and some new f:ajax tags.
> My forms contain some js functions which should be called during 
> onsubmit but unfortunately onsubmit is not called for ajax requests.
> 
> How can I specify some JS functions that should be executed before any 
> ajax call?
> I do not want to add them to a few hundred commands manually and would 
> like to define the calls on a few spots as possible.
> 
> Thanks,
> Michael
> 

Michael Heinen | 2 Feb 11:35

Re: onsumit not exeucted for ajax requests - alternative?

Hi Milo,

what's "onbegin" ?  Where do i define that?

This attribute is not specifed for h:form.
See http://myfaces.apache.org/core21/myfaces-impl/tagdoc/h_form.html

Michael

Am 02.02.2012 11:21, schrieb Milo van der Zee:
> Hello Michael,
>
> might be that 'onbegin' does what you want?
>
> MAG,
> Milo van der Zee
>
> On Thu, 2012-02-02 at 11:05 +0100, Michael Heinen wrote:
>> Hi,
>>
>> I am currently migrating an application to JSF 2.1
>>
>> I have a lot of ajax commands (richfaces) and some new f:ajax tags.
>> My forms contain some js functions which should be called during
>> onsubmit but unfortunately onsubmit is not called for ajax requests.
>>
>> How can I specify some JS functions that should be executed before any
>> ajax call?
>> I do not want to add them to a few hundred commands manually and would
>> like to define the calls on a few spots as possible.
(Continue reading)

Michael Heinen | 3 Feb 10:15

Re: onsumit not exeucted for ajax requests - alternative?

Hi,

onsubmit of the form is executed for the standard Command Button but not 
for an Ajax Button.
I tried with myFaces 2.1.5, 2.0.11 and with mojarra 2.1.6 and 2.0.8.

Here is a very simple sample:
<html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core">
<ui:composition>

<h:form id="myform" onsubmit="alert('submitted')" >
<h:outputText id="oldCounter" value="oldCounter: 
#{MyController.counter}"/><br/>
<h:outputText id="newCounter" value="newCounter: 
#{MyController.counter}"/><br/>

<h:commandButton value="AjaxButton" 
actionListener="#{MyController.increase}" >
<f:ajax render="newCounter" execute="@this"/>
</h:commandButton><br/>
<h:commandButton value="Button" actionListener="#{MyController.increase}"/>
</h:form>

</ui:composition>
</html>

@ManagedBean(name = "MyController")
(Continue reading)

Deschamps Yves | 3 Feb 14:19
Picon
Picon
Favicon

Maven Repository for portlet-bridge 1.0.1-SNAPSHOT

Hi,

Where can i found myfaces portlet-bridge 1.0.1-SNAPSHOT (Maven) ?
Thank you.

--

-- 
Yves Deschamps
CRI Pôle Web, Environnement Numérique de Travail
Bâtiment M4
Tel : 03 20 43 41 89
Fax : 03 20 43 66 25
Blog Pro : http://blogs.univ-lille1.fr/pg/blog/ydescham

Werner Punz | 6 Feb 14:02
Picon

Re: onsumit not exeucted for ajax requests - alternative?

Hi if you need to execute commands before any arbitrary ajax call
then you can add your own global ajax request listener via
jsf.ajax.addOnEvent(callback)

The callback is called three times per request, same as if you would
set it directly within the request, but on a global scale.

http://docs.oracle.com/cd/E17802_01/j2ee/javaee/javaserverfaces/2.0/docs/js-api/symbols/jsf.ajax.html

Unfortunately a deregistration is not possible within the jsf api within 
myfaces there is a way but that would break the compatibility of the 
code with Mojarra.

Werner

Am 02.02.12 11:05, schrieb Michael Heinen:
> Hi,
>
> I am currently migrating an application to JSF 2.1
>
> I have a lot of ajax commands (richfaces) and some new f:ajax tags.
> My forms contain some js functions which should be called during
> onsubmit but unfortunately onsubmit is not called for ajax requests.
>
> How can I specify some JS functions that should be executed before any
> ajax call?
> I do not want to add them to a few hundred commands manually and would
> like to define the calls on a few spots as possible.
>
> Thanks,
(Continue reading)

Michael Heinen | 6 Feb 14:12

Re: onsumit not exeucted for ajax requests - alternative?

Thanks Werner for the suggestion.

I created meanwhile a JIRA issue for this: 
https://issues.apache.org/jira/browse/MYFACES-3460

A global js listener is unfortunately not what I need.
In my case it depends on the form, whether a js should be executed 
during submission or not.
Some requests can run in parallel (e.g. autocompletion, pulls) while 
others are blocking.

Do you know why the simple onsubmit of a form is not executed for ajax 
requests?

Michael

Am 06.02.2012 14:02, schrieb Werner Punz:
> Hi if you need to execute commands before any arbitrary ajax call
> then you can add your own global ajax request listener via
> jsf.ajax.addOnEvent(callback)
>
>
> The callback is called three times per request, same as if you would
> set it directly within the request, but on a global scale.
>
>
http://docs.oracle.com/cd/E17802_01/j2ee/javaee/javaserverfaces/2.0/docs/js-api/symbols/jsf.ajax.html 
>
>
> Unfortunately a deregistration is not possible within the jsf api 
(Continue reading)

Werner Punz | 6 Feb 14:42
Picon

Re: onsumit not exeucted for ajax requests - alternative?

The onsubmit is a simple callback coming from the dom tree, it is not 
executed during ajax because there is no form submit performed.

Have in mind on some browsers you dont even get the event with special 
dom configurations (aka, simple form posts not by submit buttons etc...)
or the event cannot be blocked, so do not entirely rely on this event, 
it is flakey.

For the ajax case:

You can use the global listeners however, set yourself a marker class or 
an attribute in your form element which should trigger the listener
and if you get an ajax request you can check for this marker whether you 
should intercept with your code or not.

Here is a short pseudo code example:
function submitHandler(data) {
	if(data.status == "begin") {
		var src = data.source;
		
		var form = getParentForm(src);
		if(hasClass(form, "myMarker")) {
			intercept();
		}
         }
}

You cannot cancel the request that way, but at least you have a 
callback. Practically by throwing an error in your code the request then 
will be cancelled and an error handler will be called.
(Continue reading)

Werner Punz | 6 Feb 14:47
Picon

Re: onsumit not exeucted for ajax requests - alternative?

 > You can use the global listeners however, set yourself a marker class or
 > an attribute in your form element which should trigger the listener
 > and if you get an ajax request you can check for this marker whether you
 > should intercept with your code or not.

Just forgot to mention in your case to prevent double submits, throwing 
an error to cancel the request is perfectly valid.
For limited time double submit prevention this might be handy as well
http://www.irian.at/de/blog/-/blogs/apache-myfaces-queue-control

Werner

Am 06.02.12 14:42, schrieb Werner Punz:
> The onsubmit is a simple callback coming from the dom tree, it is not
> executed during ajax because there is no form submit performed.
>
> Have in mind on some browsers you dont even get the event with special
> dom configurations (aka, simple form posts not by submit buttons etc...)
> or the event cannot be blocked, so do not entirely rely on this event,
> it is flakey.
>
> For the ajax case:
>
> You can use the global listeners however, set yourself a marker class or
> an attribute in your form element which should trigger the listener
> and if you get an ajax request you can check for this marker whether you
> should intercept with your code or not.
>
> Here is a short pseudo code example:
> function submitHandler(data) {
(Continue reading)

Michael Heinen | 6 Feb 16:00

Re: onsumit not exeucted for ajax requests - alternative?

Werner, thanks for the explanation and pointing me to the Blog!
I'll have a look any play around with this.
Maybe RichFaces Queues are also an alternative for me because most of my 
ajax commands are from Richfaces.

Thanks,
Michael

Am 06.02.2012 14:47, schrieb Werner Punz:
> > You can use the global listeners however, set yourself a marker 
> class or
> > an attribute in your form element which should trigger the listener
> > and if you get an ajax request you can check for this marker whether 
> you
> > should intercept with your code or not.
>
> Just forgot to mention in your case to prevent double submits, 
> throwing an error to cancel the request is perfectly valid.
> For limited time double submit prevention this might be handy as well
> http://www.irian.at/de/blog/-/blogs/apache-myfaces-queue-control
>
> Werner
>
>
> Am 06.02.12 14:42, schrieb Werner Punz:
>> The onsubmit is a simple callback coming from the dom tree, it is not
>> executed during ajax because there is no form submit performed.
>>
>> Have in mind on some browsers you dont even get the event with special
>> dom configurations (aka, simple form posts not by submit buttons etc...)
(Continue reading)


Gmane