You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Marcus Büttner <mb...@buett.at> on 2010/07/02 13:35:46 UTC

concurrency problem ajax value change event and page submit

Hi,

I have the following example:

        <h:outputLabel for="val1" value="Value1"/>
        <h:inputText id="val1"
                     value="#{myBean.val1}"
                     valueChangeListener="#{myBean.val1ChangedListener}">
            <f:ajax render="myText" event="change" />
        </h:inputText>

        <h:outputText id="myText" value="#{myBean.val1}"/>

        <h:commandButton id="button" value="submit" 
action="#{myBean.action}"/>

Now I fill out the input field and directly press Enter for submit or 
click submit button without leaving the input field before. Now two 
requests are send parallel (page submit and ajax value change event).
The problem is I found four different behaviours which comes random 
(with firefox):

1.) 1. request: value change listener is called. 2. request actions is 
called (that's what I expected)
2.) 1. request value change listener is called. but the action request 
is missing.
3.) 1. action request get's in an fires the value change event and calls 
the action. but than this message pops up:
"httpError-httpError-Request failed- Note, this message is only sent, 
because project sage is development and no other error listeners are 
registered"
4.) 1. request value change lister is called. 2. request also value 
change listener is called and than the action is called. the message 
above also pops up.

In IE sometimes the action is called, sometimes not. The value change 
listener is always called. But this error dialog (like in firefox) is 
never shown.

Is there any explanation? How could I force a fix behaviour?

Thx for help.

Marcus


Re: concurrency problem ajax value change event and page submit

Posted by Werner Punz <we...@gmail.com>.
Yes the issue is that you use a command button which in case of a single 
button maps automatically to input type="submit" if you hit enter
the ajax request is issued and subsequently parallely the full submit is 
issued as well.
You can resolve that by using commandlinks or <h:commandButton 
type="button"> which should resolve the auto enter issue introduced by 
the input type="submit".

The problem with the error is not a bug but an xhr request issued 
asynchronously then a page refresh triggered at the same time which is 
more a problem of the spec relying on parallel xhr requests. MyFaces 
then correctly issues an http error due to the timing issue triggered 
because of the xhr request having failed due to the subsequent refresh 
issued. But as usual with those timing problems they occur depending on 
the current state of the issue, hence in a non reproducable manner.

So the final behavior after fixing is

change + enter -> onchange
button press -> action



Werner




Am 02.07.10 13:35, schrieb Marcus Büttner:
> Hi,
>
> I have the following example:
>
> <h:outputLabel for="val1" value="Value1"/>
> <h:inputText id="val1"
> value="#{myBean.val1}"
> valueChangeListener="#{myBean.val1ChangedListener}">
> <f:ajax render="myText" event="change" />
> </h:inputText>
>
> <h:outputText id="myText" value="#{myBean.val1}"/>
>
> <h:commandButton id="button" value="submit" action="#{myBean.action}"/>
>
> Now I fill out the input field and directly press Enter for submit or
> click submit button without leaving the input field before. Now two
> requests are send parallel (page submit and ajax value change event).
> The problem is I found four different behaviours which comes random
> (with firefox):
>
> 1.) 1. request: value change listener is called. 2. request actions is
> called (that's what I expected)
> 2.) 1. request value change listener is called. but the action request
> is missing.
> 3.) 1. action request get's in an fires the value change event and calls
> the action. but than this message pops up:
> "httpError-httpError-Request failed- Note, this message is only sent,
> because project sage is development and no other error listeners are
> registered"
> 4.) 1. request value change lister is called. 2. request also value
> change listener is called and than the action is called. the message
> above also pops up.
>
> In IE sometimes the action is called, sometimes not. The value change
> listener is always called. But this error dialog (like in firefox) is
> never shown.
>
> Is there any explanation? How could I force a fix behaviour?
>
> Thx for help.
>
> Marcus
>
>