Getters inside f:verbatim called before form submission

青春壹個敷衍的年華 提交于 2019-11-29 12:01:39
BalusC

As per your own answer on this topic:

I removed the f:verbatim tag, and now it works properly. I still don't understand why it has caused this behaviour though.

The <f:verbatim> was introduced in JSF 1.0 a long time back with the sole purpose to be able to include plain HTML in the JSF component tree. On JSF 1.0 (and 1.1), when the component tree get built, all the plain HTML was ignored. The page get rendered with all the plain HTML first and then the rendered HTML of JSF components thereafter. So for example

<p>Hello</p>
<h:inputText />
<p>World</p>
<h:outputText value="outputtext" />
<p>This is weird</p>

get rendered as

<p>Hello</p>
<p>World</p>
<p>This is weird</p>
<input type="text" />
outputtext    

The <f:verbatim> allowed developers to take plain HTML into the JSF component tree, so that they get rendered "in sync" as you'd expect from the coding.

<f:verbatim><p>Hello</p></f:verbatim>
<h:inputText />
<f:verbatim><p>World</p></f:verbatim>
<h:outputText value="outputtext" />
<f:verbatim><p>This is weird</p></f:verbatim>

They however get inlined during view build time, not during view render time. This is the cause of your problem, the getters get invoked during restore view phase instead of render response phase.

Since JSF 1.2, with the improved view handler, it was possible to inline plain HTML "in sync" without hassling with ugly <f:verbatim> tags. So it's not needed anymore. There are also no useful use cases for the tag anymore, expect of possibly some premature performance optimizations, but still then, you should not use it in combination with dynamic data as obtained by Expression Language.

Related questions:

Put an immediate attribute set to true on the commandButton.

<h:commandButton id="gameSelector" value="Play" action="#{gameBean.changeGame}" immediate="true" />

It will execute the method in the ApplyRequestValues phase then.

I removed the f:verbatim tag, and now it works properly. I still don't understand why it has caused this behaviour though.

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