You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Leonardo Uribe (JIRA)" <de...@myfaces.apache.org> on 2014/01/02 22:00:51 UTC

[jira] [Commented] (MYFACES-3836) f:ajax disabled=false in commandButton with onclick prevents form submission

    [ https://issues.apache.org/jira/browse/MYFACES-3836?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13860753#comment-13860753 ] 

Leonardo Uribe commented on MYFACES-3836:
-----------------------------------------

I checked the patch and it is correct. I can remember the problem long time ago in 2.0. ClientBehavior does not expose isDisabled(), so the reasoning was there is no way to know when a client behavior is disabled or not. The idea introduced by the patch is if there is no script, we can assume there is no submitting behavior by the ClientBehavior, and in that way we can ignore the value provided as hint.

Anyway, the patch requires some changes, because we need to preserve the behavior under multiple ClientBehavior instances. If there are 2 client behaviors and 1 is submitting and the second is disabled, the first one cannot be disabled by the second one. To do the fix it is enough to add a simple null check in the block that sets "submitting" variable.

I have tested this behavior against Mojarra and in that case it do what is proposed in this issue, so the fix will align the code with the reference.

This fix needs to be added in 2.0.x, 2.1.x and 2.2.x

> f:ajax disabled=false in commandButton with onclick prevents form submission
> ----------------------------------------------------------------------------
>
>                 Key: MYFACES-3836
>                 URL: https://issues.apache.org/jira/browse/MYFACES-3836
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: JSR-314
>    Affects Versions: 2.2.0-beta
>         Environment: MyFaces 2.2.0-beta, WildFly 8.0.0.Beta1, Jdk 1.7.0_25, Chrome 30.0.1599.101 m
>            Reporter: Ali Cheaito
>             Fix For: 2.2.0
>
>         Attachments: MYFACES-3836.patch
>
>
> For <f:ajax> with disabled=true inside of a <h:commandButton> with an onclick function, MyFaces renders return=false after an unnecessary jsf.util.chain() call in the rendered <input> onclick, effectively preventing form submission. Consider the following simple commandButton
> 	   <h:commandButton id="button1" value="AjaxTest" action="index" onclick="alert('test')">
> 	       <f:ajax disabled="true"  />
> 	   </h:commandButton>	
> This will render as follows:
>     <input id="form1:button1" name="form1:button1" type="submit" value="AjaxTest" onclick="jsf.util.chain(document.getElementById('form1:button1'), event,'alert(\'test\');'); return false;">
> Clicking the button will neither trigger an ajax request, which it shouldn't, nor trigger a form submit, which it should. 
> Removing the <f:ajax> tag entirely renders the following functional submit button:
>     <input id="form1:button1" name="form1:button1" type="submit" value="AjaxTest" onclick="var cf = function(){alert('test')};var oamSF = function(){};return (cf.apply(this, [])==false)? false : oamSF.apply(this, []); ">



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)