f:verbatim 内的 Getter 在表单提交之前调用
我有以下页面:
<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. 页面刷新。
我的问题在于 1. 和 2 的顺序。changeGame 修改 getGameId 和 getHtmlPage 使用的 gameBean 变量。因此,我希望它首先执行,以便刷新其他面板时,它们包含正确的数据。
请注意,此问题似乎仅发生在 gameDiv 元素内的调用(其他变量已正确刷新)。
您是否知道我可以做什么来恢复 1. 和 2. 的顺序,以便 ChangeGame() 方法成为第一个被调用的方法?
我在 Tomcat 7.0 上使用 JavaServer Faces 2.0。
提前致谢
I have the following page:
<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>
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.
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.
Please note that this issue seems to occur only for the call within the gameDiv element (other variables are properly refreshed).
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?
I am using JavaServer Faces 2.0 on Tomcat 7.0.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据您自己关于此主题的答案:
很早以前就在 JSF 1.0 中引入,其唯一目的是能够包含JSF 组件树中的纯 HTML。在 JSF 1.0(和 1.1)上,当构建组件树时,所有纯 HTML 都被忽略。首先使用所有纯 HTML 呈现页面,然后使用 JSF 组件呈现的 HTML。。例如,渲染为
允许开发人员将纯 HTML 放入 JSF 组件树中,以便它们按照您对编码的期望“同步”渲染。然而,它们在视图构建时间期间内联,而不是在视图渲染时间期间内联。这是问题的原因,吸气剂在恢复视图阶段而不是渲染响应阶段被调用。
从 JSF 1.2 开始,通过改进的视图处理程序,可以“同步”内联纯 HTML,而不必担心难看的
标记。所以不再需要了。该标签也不再有有用的用例,可能会出现一些过早的性能优化,但仍然不应该将其与表达式语言获得的动态数据结合使用。相关问题:
As per your own answer on this topic:
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 exampleget rendered as
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.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:
将命令按钮上的立即属性设置为 true。
然后它将执行ApplyRequestValues阶段的方法。
Put an immediate attribute set to true on the commandButton.
It will execute the method in the ApplyRequestValues phase then.
我删除了 f:verbatim 标签,现在它可以正常工作了。我仍然不明白为什么它会导致这种行为。
I removed the f:verbatim tag, and now it works properly. I still don't understand why it has caused this behaviour though.