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/06/29 11:05:53 UTC

Problem with Ajax and ViewScope

Hi,

a small example with two input fields, both with valueChangeListener and 
a f:ajax for rerendering the output field:

<h:form id="myForm">
        <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:outputLabel for="val2" value="Value2"/>
        <h:inputText id="val2"
                     value="#{myBean.val2}"
                     valueChangeListener="#{myBean.val2ChangedListener}">
            <f:ajax render="myText" event="change" />
        </h:inputText>

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

Everything works fine, until my Bean is ViewScoped. Every time I change 
a value in the input fields, this value is rendered in my output. But 
all changes before are lost.
E.g.
change value1 to "value1" causes output = "value1"
change value2 to "value2" causes output = "value2" (but it should be: 
"value1 value2")

I've debugged and found, that in restoreView always the first ViewState 
(which was active after entering the page) is restored. It looks like, 
the javax.faces.ViewState component in html DOM tree is not updated by 
an ajax request and so always the first ViewState is restored instead of 
the last.

I'm using the last MyFaces Snapshot (2.0.1-SNAPSHOT).

Does anyone has an idea? Or is something wrong in my code?

Thx for help.

Regards Marcus




Re: Problem with Ajax and ViewScope

Posted by Marcus Büttner <mb...@buett.at>.
Hi Werner,

I tested the problem with newest snapshot from today and it works. It 
looks like it was a temporary bug in the trunk. ;-)

Thx for your help!

Marcus

Werner Punz schrieb:
> Ok I gave the example a testrun and could not reproduce the problem 
> anymore, I assume one of following issues
>
> a) It was a temporary bug in the trunk (I did an svn update on the 
> latest codebase to check)
>
> b) You might have forgotten to make the ViewScoped bean serializable.
> (In which case the latest trunk issues an error and the latest ajax 
> scripts as well)
>
> c) Your event handlers supress the phases
>
> In either case with a stock serializable page scoped bean thew
> example works as expected. I have closed the issue for now, please 
> give me notice if the latest trunk works for you, if not we will 
> investigate a little bit more.
>
> Werner
>
>
>
>
> Am 29.06.10 12:56, schrieb Marcus Büttner:
>> Thx for your response. I created an issue.
>>
>> https://issues.apache.org/jira/browse/MYFACES-2776
>>
>> Marcus
>>
>> Werner Punz schrieb:
>>> Hi there is some optimization work going on currently on the
>>> viewstate, you might have triggered a bug in the trunk, can you file a
>>> jira issue on this one?
>>>
>>>
>>> Werner
>>>
>>>
>>> Am 29.06.10 11:05, schrieb Marcus Büttner:
>>>> Hi,
>>>>
>>>> a small example with two input fields, both with 
>>>> valueChangeListener and
>>>> a f:ajax for rerendering the output field:
>>>>
>>>> <h:form id="myForm">
>>>> <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:outputLabel for="val2" value="Value2"/>
>>>> <h:inputText id="val2"
>>>> value="#{myBean.val2}"
>>>> valueChangeListener="#{myBean.val2ChangedListener}">
>>>> <f:ajax render="myText" event="change" />
>>>> </h:inputText>
>>>>
>>>> <h:outputText id="myText" value="#{myBean.val1} #{myBean.val2}"/>
>>>> </h:form>
>>>>
>>>> Everything works fine, until my Bean is ViewScoped. Every time I 
>>>> change
>>>> a value in the input fields, this value is rendered in my output. But
>>>> all changes before are lost.
>>>> E.g.
>>>> change value1 to "value1" causes output = "value1"
>>>> change value2 to "value2" causes output = "value2" (but it should be:
>>>> "value1 value2")
>>>>
>>>> I've debugged and found, that in restoreView always the first 
>>>> ViewState
>>>> (which was active after entering the page) is restored. It looks like,
>>>> the javax.faces.ViewState component in html DOM tree is not updated by
>>>> an ajax request and so always the first ViewState is restored 
>>>> instead of
>>>> the last.
>>>>
>>>> I'm using the last MyFaces Snapshot (2.0.1-SNAPSHOT).
>>>>
>>>> Does anyone has an idea? Or is something wrong in my code?
>>>>
>>>> Thx for help.
>>>>
>>>> Regards Marcus
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>


Re: Problem with Ajax and ViewScope

Posted by Werner Punz <we...@gmail.com>.
Ok I gave the example a testrun and could not reproduce the problem 
anymore, I assume one of following issues

a) It was a temporary bug in the trunk (I did an svn update on the 
latest codebase to check)

b) You might have forgotten to make the ViewScoped bean serializable.
(In which case the latest trunk issues an error and the latest ajax 
scripts as well)

c) Your event handlers supress the phases

In either case with a stock serializable page scoped bean thew
example works as expected. I have closed the issue for now, please give 
me notice if the latest trunk works for you, if not we will investigate 
a little bit more.

Werner




Am 29.06.10 12:56, schrieb Marcus Büttner:
> Thx for your response. I created an issue.
>
> https://issues.apache.org/jira/browse/MYFACES-2776
>
> Marcus
>
> Werner Punz schrieb:
>> Hi there is some optimization work going on currently on the
>> viewstate, you might have triggered a bug in the trunk, can you file a
>> jira issue on this one?
>>
>>
>> Werner
>>
>>
>> Am 29.06.10 11:05, schrieb Marcus Büttner:
>>> Hi,
>>>
>>> a small example with two input fields, both with valueChangeListener and
>>> a f:ajax for rerendering the output field:
>>>
>>> <h:form id="myForm">
>>> <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:outputLabel for="val2" value="Value2"/>
>>> <h:inputText id="val2"
>>> value="#{myBean.val2}"
>>> valueChangeListener="#{myBean.val2ChangedListener}">
>>> <f:ajax render="myText" event="change" />
>>> </h:inputText>
>>>
>>> <h:outputText id="myText" value="#{myBean.val1} #{myBean.val2}"/>
>>> </h:form>
>>>
>>> Everything works fine, until my Bean is ViewScoped. Every time I change
>>> a value in the input fields, this value is rendered in my output. But
>>> all changes before are lost.
>>> E.g.
>>> change value1 to "value1" causes output = "value1"
>>> change value2 to "value2" causes output = "value2" (but it should be:
>>> "value1 value2")
>>>
>>> I've debugged and found, that in restoreView always the first ViewState
>>> (which was active after entering the page) is restored. It looks like,
>>> the javax.faces.ViewState component in html DOM tree is not updated by
>>> an ajax request and so always the first ViewState is restored instead of
>>> the last.
>>>
>>> I'm using the last MyFaces Snapshot (2.0.1-SNAPSHOT).
>>>
>>> Does anyone has an idea? Or is something wrong in my code?
>>>
>>> Thx for help.
>>>
>>> Regards Marcus
>>>
>>>
>>>
>>>
>>
>>
>
>



Re: Problem with Ajax and ViewScope

Posted by Werner Punz <we...@gmail.com>.
Thanks a lot I will start to investigate on my side (javascript) if 
something is wrong there (which I doubt) today.
I assume the problem is originated by some of the performance 
optimisations done on the partial tree, and will be gone in a few days.

Werner


Am 29.06.10 12:56, schrieb Marcus Büttner:
> Thx for your response. I created an issue.
>
> https://issues.apache.org/jira/browse/MYFACES-2776
>
> Marcus
>
> Werner Punz schrieb:
>> Hi there is some optimization work going on currently on the
>> viewstate, you might have triggered a bug in the trunk, can you file a
>> jira issue on this one?
>>
>>
>> Werner
>>
>>
>> Am 29.06.10 11:05, schrieb Marcus Büttner:
>>> Hi,
>>>
>>> a small example with two input fields, both with valueChangeListener and
>>> a f:ajax for rerendering the output field:
>>>
>>> <h:form id="myForm">
>>> <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:outputLabel for="val2" value="Value2"/>
>>> <h:inputText id="val2"
>>> value="#{myBean.val2}"
>>> valueChangeListener="#{myBean.val2ChangedListener}">
>>> <f:ajax render="myText" event="change" />
>>> </h:inputText>
>>>
>>> <h:outputText id="myText" value="#{myBean.val1} #{myBean.val2}"/>
>>> </h:form>
>>>
>>> Everything works fine, until my Bean is ViewScoped. Every time I change
>>> a value in the input fields, this value is rendered in my output. But
>>> all changes before are lost.
>>> E.g.
>>> change value1 to "value1" causes output = "value1"
>>> change value2 to "value2" causes output = "value2" (but it should be:
>>> "value1 value2")
>>>
>>> I've debugged and found, that in restoreView always the first ViewState
>>> (which was active after entering the page) is restored. It looks like,
>>> the javax.faces.ViewState component in html DOM tree is not updated by
>>> an ajax request and so always the first ViewState is restored instead of
>>> the last.
>>>
>>> I'm using the last MyFaces Snapshot (2.0.1-SNAPSHOT).
>>>
>>> Does anyone has an idea? Or is something wrong in my code?
>>>
>>> Thx for help.
>>>
>>> Regards Marcus
>>>
>>>
>>>
>>>
>>
>>
>
>



Re: Problem with Ajax and ViewScope

Posted by Marcus Büttner <mb...@buett.at>.
Thx for your response. I created an issue.

https://issues.apache.org/jira/browse/MYFACES-2776

Marcus

Werner Punz schrieb:
> Hi there is some optimization work going on currently on the 
> viewstate, you might have triggered a bug in the trunk, can you file a 
> jira issue on this one?
>
>
> Werner
>
>
> Am 29.06.10 11:05, schrieb Marcus Büttner:
>> Hi,
>>
>> a small example with two input fields, both with valueChangeListener and
>> a f:ajax for rerendering the output field:
>>
>> <h:form id="myForm">
>> <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:outputLabel for="val2" value="Value2"/>
>> <h:inputText id="val2"
>> value="#{myBean.val2}"
>> valueChangeListener="#{myBean.val2ChangedListener}">
>> <f:ajax render="myText" event="change" />
>> </h:inputText>
>>
>> <h:outputText id="myText" value="#{myBean.val1} #{myBean.val2}"/>
>> </h:form>
>>
>> Everything works fine, until my Bean is ViewScoped. Every time I change
>> a value in the input fields, this value is rendered in my output. But
>> all changes before are lost.
>> E.g.
>> change value1 to "value1" causes output = "value1"
>> change value2 to "value2" causes output = "value2" (but it should be:
>> "value1 value2")
>>
>> I've debugged and found, that in restoreView always the first ViewState
>> (which was active after entering the page) is restored. It looks like,
>> the javax.faces.ViewState component in html DOM tree is not updated by
>> an ajax request and so always the first ViewState is restored instead of
>> the last.
>>
>> I'm using the last MyFaces Snapshot (2.0.1-SNAPSHOT).
>>
>> Does anyone has an idea? Or is something wrong in my code?
>>
>> Thx for help.
>>
>> Regards Marcus
>>
>>
>>
>>
>
>


Re: Problem with Ajax and ViewScope

Posted by Werner Punz <we...@gmail.com>.
Hi there is some optimization work going on currently on the viewstate, 
you might have triggered a bug in the trunk, can you file a jira issue 
on this one?


Werner


Am 29.06.10 11:05, schrieb Marcus Büttner:
> Hi,
>
> a small example with two input fields, both with valueChangeListener and
> a f:ajax for rerendering the output field:
>
> <h:form id="myForm">
> <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:outputLabel for="val2" value="Value2"/>
> <h:inputText id="val2"
> value="#{myBean.val2}"
> valueChangeListener="#{myBean.val2ChangedListener}">
> <f:ajax render="myText" event="change" />
> </h:inputText>
>
> <h:outputText id="myText" value="#{myBean.val1} #{myBean.val2}"/>
> </h:form>
>
> Everything works fine, until my Bean is ViewScoped. Every time I change
> a value in the input fields, this value is rendered in my output. But
> all changes before are lost.
> E.g.
> change value1 to "value1" causes output = "value1"
> change value2 to "value2" causes output = "value2" (but it should be:
> "value1 value2")
>
> I've debugged and found, that in restoreView always the first ViewState
> (which was active after entering the page) is restored. It looks like,
> the javax.faces.ViewState component in html DOM tree is not updated by
> an ajax request and so always the first ViewState is restored instead of
> the last.
>
> I'm using the last MyFaces Snapshot (2.0.1-SNAPSHOT).
>
> Does anyone has an idea? Or is something wrong in my code?
>
> Thx for help.
>
> Regards Marcus
>
>
>
>