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.
精彩评论