Upgrade: 6.1.15 to 6.2 <f:viewAction> gets broken (fired on each postback) - FIXED

UI Components for JSF
Post Reply
AndrewGr
Posts: 19
Joined: 22 Mar 2016, 08:49
Location: Hong Kong

14 Mar 2018, 08:04

Hi PrimeFaces team,

After upgrading from 6.1.15 to 6.2, the <f:viewAction> is being fired on each postback, meanwhile on 6.1.X it behaves exactly as it is stated in the documentation for "onPostback" property of this control: "By default, a view action is not executed on postback. If your application is decidedly stateless, you may need the view action to execute on any type of request. The default value is false."

The code sample is the following:

Code: Select all

<ui:composition ... />

    <f:metadata>
        <f:viewAction action="#{bean.method}" />
    </f:metadata>
    ...
    ...
    ...
    <p:commandButton id="btnEdit" action="#{bean.doEdit}" process="@this" update="@form" immediate="true" value="Edit" icon="fa fa-fw fa-pencil" styleClass="secondary-btn" />

</ui:composition>
Can you please share any thoughts whether it is issue on the PF 6.2 side or in my application?

Thank you!
Last edited by AndrewGr on 21 Apr 2018, 07:52, edited 1 time in total.
Best regards,
Andrew

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

15 Mar 2018, 16:35

Sure it is the only thing you changed? Not a new JSF version too 'by accident'?

AndrewGr
Posts: 19
Joined: 22 Mar 2016, 08:49
Location: Hong Kong

15 Apr 2018, 04:13

Thank you for reply!

Yes, absolutely! I have just repeated the same scenario by upgrading 6.1.16 to 6.2.2. The issue is absolutely the same. No single other component or piece of code was changed.

Any suggestions?

Thank you!
Best regards,
Andrew

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

16 Apr 2018, 09:50

f:viewAction (and the docs part) is not PrimeFaces, so I 1000% want to exclude things. If you start a new small clean project without PrimeFaces and use an h:commandButton with f:ajax instead of a p:commandButton, you don't have this problem? And if in this new project you just add PrimeFaces (not using any PrimeFaces tags) does it fail then? And if you then change the h:commandButton/f:ajax to a p:commandButton?

The reason I ask this is that using the f:metadata inside a composition like you do is not really correct/the best... https://stackoverflow.com/questions/985 ... -fmetadata

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

16 Apr 2018, 10:31

It would be great if you could fork primefaces-test and provide a example ;)
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

AndrewGr
Posts: 19
Joined: 22 Mar 2016, 08:49
Location: Hong Kong

17 Apr 2018, 05:01

tandraschko wrote:
16 Apr 2018, 10:31
It would be great if you could fork primefaces-test and provide a example ;)
Sure, will do so as this functionality is super crucial for my project and without having it working as before - I can not upgrade to PF 6.2.
Will work on it and provide test projects soon!

Thanks!
Best regards,
Andrew

AndrewGr
Posts: 19
Joined: 22 Mar 2016, 08:49
Location: Hong Kong

17 Apr 2018, 05:07

kukeltje wrote:
16 Apr 2018, 09:50
f:viewAction (and the docs part) is not PrimeFaces, so I 1000% want to exclude things. If you start a new small clean project without PrimeFaces and use an h:commandButton with f:ajax instead of a p:commandButton, you don't have this problem? And if in this new project you just add PrimeFaces (not using any PrimeFaces tags) does it fail then? And if you then change the h:commandButton/f:ajax to a p:commandButton?
Thank you! Will run all proposed tests and provide the results.
kukeltje wrote:
16 Apr 2018, 09:50
The reason I ask this is that using the f:metadata inside a composition like you do is not really correct/the best... https://stackoverflow.com/questions/985 ... -fmetadata
Thank you for pointing out on this post! I didn't know it. Will fix it by placing f:metadata as recommended in the StackOverflow post! Thanks!
Best regards,
Andrew

AndrewGr
Posts: 19
Joined: 22 Mar 2016, 08:49
Location: Hong Kong

21 Apr 2018, 07:50

Hi guys,

Good news: looks like I was able to fix the issue. :)

I was able to locate what exactly causes the issue described in my initial post: everything is because of the:

Code: Select all

<p:outputPanel deferred="true">
More specifically, because of the param: deferred="true", when it is set to deferred="false" - everything works fine.

Based on the primefaces-test project, the test.xhtml that reproduces the issue looks like in the listing below:

Code: Select all

    <f:view>

        <f:metadata>
            <f:viewAction action="#{testView.onPageLoadOnly}" />
        </f:metadata>

        <h:head>   
            <title>PrimeFaces Test</title>
        </h:head>

        <h:body>

            <h:form id="f1">

                <h1>#{testView.testString}</h1>

                <h:panelGroup layout="block" id="block1">

                    <p:outputPanel deferred="true">
                        <p:outputLabel value="#{testView.time}" />
                    </p:outputPanel>

                    <p:commandButton value="TestAction" action="#{testView.testAction()}" process="@this" update="@form" />

                </h:panelGroup>

            </h:form>

        </h:body>

    </f:view>
As result - it caused <f:viewAction action="#{testView.onPageLoadOnly}" /> to be executed on each p:commandButton click.
In console it looks like this:
https://www.dropbox.com/s/czgpsmgt8dpx6 ... n.jpg?dl=0

But the expected behavior is:
https://www.dropbox.com/s/b856ypaitpvnl ... d.jpg?dl=0

In this case both versions of PrimeFaces 6.1 and 6.2 were affected. Honestly, for a long time I had concerns re behavior of the p:outputPanel with deferred="true" param (due to the number of requests it generates during self-update), thus probably it is time to get rid of it...

The primefaces-test project can be downloaded here: https://www.dropbox.com/sh/3insuw8tul9h ... RSGaa?dl=0

Any thoughts or updates are highly welcome! ;)
By the way - I have fixed the <f:metadata> tag location and updated the master template respectively, so now f:metadata placed in proper place.

Thank you!
Best regards,
Andrew

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 37 guests