f:viewAction ignored, when commandButton navigates to page

孤街浪徒 提交于 2019-12-01 18:35:20
BalusC

The <f:viewAction onPostback="true"> applies only on postbacks on the very same view. I.e. it runs only when a <h:form> in the very same view has been submitted. The <f:viewAction> is never intented to be executed upon POST navigation triggered by a submit of a <h:form> of another view. Moreover, the term "postback" in the attribute name also confirms this. This term means in web development world "a POST request on the URL of the page itself".

You need to open it by a GET request instead of a POST request. Replace the <h:commandButton> by <h:button>:

<h:button outcome="viewActionStart.xhtml" value="To f:viewAction Page" />

(note: the <h:form> is not necessary anymore)

Or, if you really intend to perform a POST request first for some unclear reason (it would have been a bit more understandable if you were invoking a bean action method, but you're here merely navigating, so the whole POST request doesn't make any sense), then let it send a redirect:

<h:commandButton action="viewActionStart.xhtml?faces-redirect-true" value="To f:viewAction Page" />

Either way, the URL should now be properly reflected in address bar. This was at its own indeed a strong hint that you was donig things the wrong way ;)

See also:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!