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")
@SessionScoped
public class MyController{
  private int counter = 1;
  public int getCounter() {
    return counter;
  }
  public void increase(ActionEvent ae) {
    counter++;
  }
}

Is it a bug and should I add it to JIRA?
Is there any workaround to execute the js of the outer form for ajax commands?
It was working well with JSF 1.2 and richfaces 3.3.3, but now I'm stuck

Michael


Am 02.02.2012 12:09, schrieb Milo van der Zee:
Hello Michael,

you are completely right. I have the onbegin defined on every action
initiating component but that is precisely what you don't want. That
would result in very much changes...

<a4j:status id="status" startText="" stopText=""
onstart="showAjaxActive();" onstop="hideAjaxActive();"
onerror="handleError(event);"/>

This does handle every ajax call but then it has nothing to do with form
submissions.

I'm actually surprised that onsubmit does not work. Isn't it just a bug?

MAG,
Milo

On Thu, 2012-02-02 at 11:35 +0100, Michael Heinen wrote:
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.

Thanks,
Michael






Reply via email to