开发者

<ui:include> with dynamic src does not invoke setters on backingbean

开发者 https://www.devze.com 2023-02-18 20:36 出处:网络
I have a first.jsf in which I include second.xhtml in the following way: <ui:include src=\"#{firstBean.srcForSecond}\" />

I have a first.jsf in which I include second.xhtml in the following way:

<ui:include src="#{firstBean.srcForSecond}" />

This works fine and renders the contents of second.jsf. I included it using EL as the included content changes based on some conditions.

My second.xhtml contains a simple input text box:

<h:inputText id="firstname" value="#{secondBean.firstName}" />

When I load the page the value for firstname is rendered properly. However, when I change the value in the text box and submit, the setter on the backing bean is never invoked.

However if I change the ui:include in the following way, it works:

<ui:include src="second.xhtml" />

But, I require to use EL expression as it could be sec开发者_运维百科ond.xhtml or third.xhtml based on some conditions.

Can anybody explain whats going on and how to fix it?


You need to make the #{firstBean} a @ViewScoped bean instead of a @RequestScoped one. This way you ensure that #{firstBean.srcForSecond} evaluates the same in the subsequent request. It's namely re-evaluated during apply request values phase of the form submit. If it evaluates differently, then the originally included components can't be located and nothing will be set/invoked.

0

精彩评论

暂无评论...
验证码 换一张
取 消