提交表单之前调用f:verbatim中的吸气剂 [英] Getters inside f:verbatim called before form submission

查看:118
本文介绍了提交表单之前调用f:verbatim中的吸气剂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下页面:

<h:form id="gameSelectionForm">
    <h:selectOneMenu id="gameSelection">
        <f:selectItems value="#{gameBean.gameIds}" />
    </h:selectOneMenu>
    <h:commandButton id="gameSelector" value="Play" action="#{gameBean.changeGame}"  />
</h:form>

<h:panelGroup id="gameDiv">
    <f:verbatim>
        <iframe src="/levelup/resources/games/#{gameBean.gameId}/#{gameBean.htmlPage}"  width="700px" height="800px" frameborder="0"/>
    </f:verbatim>
</h:panelGroup>

当我单击"gameSelector"按钮时,这是事件的顺序: 1. gameBean.getGameId和gameBean.getHtmlPage被调用 2. gameBean.changeGame被调用 3.页面刷新.

When I click on the "gameSelector" button, here is the sequence of events: 1. gameBean.getGameId and gameBean.getHtmlPage are called 2. gameBean.changeGame is called 3. The page is refreshed.

我的问题按1和2的顺序排列.changeGame修改了getGameId和getHtmlPage使用的gameBean变量.因此,我希望它首先执行,以便刷新其他面板时,它们包含正确的数据.

My issues lies in the order of 1. and 2. The changeGame modifies a gameBean variable that is used by the getGameId and getHtmlPage. I thus want to it execute first, so that when other panels are refreshed, they contain the proper data.

请注意,此问题似乎仅发生在gameDiv元素内的调用中(其他变量已正确刷新).

Please note that this issue seems to occur only for the call within the gameDiv element (other variables are properly refreshed).

您对我可以做些什么来恢复1.和2.的顺序有任何想法,以便changeGame()方法是第一个被调用的方法?

Would you have any idea as to what I could do to revert the order of 1. and 2., so that the changeGame() method is the first one called?

我正在Tomcat 7.0上使用JavaServer Faces 2.0.

I am using JavaServer Faces 2.0 on Tomcat 7.0.

预先感谢

推荐答案

根据您自己的

我删除了f:verbatim标记,现在它可以正常工作了.我仍然不明白为什么它会导致这种行为.

<f:verbatim>是很久以前在JSF 1.0中引入的,其唯一目的是能够在JSF组件树中包括纯HTML.在JSF 1.0(和1.1)上,当构建组件树时,所有纯HTML都将被忽略.首先用所有普通HTML呈现页面,然后用然后呈现JSF组件的HTML.例如

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>

呈现为

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

<f:verbatim>允许开发人员将纯HTML放入JSF组件树中,以便按照您的期望从编码中同步"呈现它们.

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>

但是,它们在视图 build 期间内联,而不是在视图渲染期间内联.这是造成问题的原因,在还原视图阶段而不是渲染响应阶段会调用getter.

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.

自JSF 1.2起,使用改进的视图处理程序,可以同步"内联纯HTML,而不会麻烦地使用<f:verbatim>标记.因此不再需要.该标记也不再有有用的用例,可能会进行一些过早的性能优化,但是仍然如此,您不应该将其与Expression Language获得的动态数据结合使用.

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.

这篇关于提交表单之前调用f:verbatim中的吸气剂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆