[ 
http://issues.apache.org/jira/browse/MYFACES-401?page=comments#action_12330053 
] 

Paul Klaer commented on MYFACES-401:
------------------------------------

For my understanding the solution without the second if condition is the 
clearest one...

Zhong Li executes the onsubmit statement on the a tag with the second if clause 
and if it returns true he executes the form onsubmit statement a second time!

You can check this concerning the second if statement:

put this to the form onsubmit tag: <form target="" onsubmit="alert('submit 
form');return true;"

put after the second if condition to the statement just before the onsubmit() 
statement: "...alert('submit now');document.forms['form1'].onsubmit();}}else..."

If you use Zhong Li's code you get three messages: -->> submit form (because 
executed in the second if condition to get the value true) -->> submit now -->> 
!! submit form !! (because the if condition was true execute the onsubmit code 
again)

If you don't check the second if statement and execute this statement after the 
first condition the browser is doing what you want. Because now only the 
executed statement on the form onsubmit tag is executed ones its returning true 
on the end and it then submits the form. If the form onsubmit returns false it 
never executes the form.

Just try it and remove the second if statment and you get the following 
messages: -->> submit now -->> submit form.

And this is what I would expect because you don't know what users would do in 
this form onsubmit tag code snippets... its better to execute them only one 
time I think....


> CommandLink tag override onsubmit function of Form
> --------------------------------------------------
>
>          Key: MYFACES-401
>          URL: http://issues.apache.org/jira/browse/MYFACES-401
>      Project: MyFaces
>         Type: Bug
>   Components: Implementation
>     Versions: 1.1.0
>  Environment: Tomcat 5.0.28
>     Reporter: Zhong Li
>     Assignee: Martin Marinschek
>     Priority: Critical
>  Attachments: bugfix_myfaces-401.txt
>
> I have java script onsubmit in <h:form>, when I use commandLink tag, even 
> onsubmit return false, the form still submitted. I checked javasctipt, If I 
> am right, the bug should be here,
> JSF generate Javascript for each commandLink like,
> clear_unitItemViewList();
> document.forms['unitItemViewList'].elements['autoScroll'].value=getScrolling();
> document.forms['unitItemViewList'].elements['unitItemViewList:_link_hidden_'].value='unitItemViewList:_id49_0:_id72';
> if(document.forms['unitItemViewList'].onsubmit){document.forms['unitItemViewList'].onsubmit();}
> document.forms['unitItemViewList'].submit();
> return false;
> ----------------------
> so problem it will be caused by 
> if(document.forms['unitItemViewList'].onsubmit){document.forms['unitItemViewList'].onsubmit();}
> document.forms['unitItemViewList'].submit(); //the form submitted!!!!!!
> it should be 
> if(document.forms['unitItemViewList'].onsubmit)
> {
>     if( document.forms['unitItemViewList'].onsubmit() )
>     {
>        document.forms['unitItemViewList'].submit();
>     }
> }
> else
> {
>    document.forms['unitItemViewList'].submit();
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to