gpt4 book ai didi

java - f :verbatim called before form submission 内的 setter/getter

转载 作者:行者123 更新时间:2023-11-30 06:36:43 24 4
gpt4 key购买 nike

我有以下页面:

<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.getHtmlPage2.调用gameBean.changeGame3.页面刷新。

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

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

您知道我可以做些什么来恢复 1. 和 2. 的顺序,以便 ChangeGame() 方法成为第一个调用的方法吗?

我在 Tomcat 7.0 上使用 JavaServer Faces 2.0。

提前致谢

最佳答案

根据您自己的answer关于这个主题:

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

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

<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 组件树中,以便它们按照您对编码的期望“同步”呈现。

<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>

但是,它们在 View 构建时间期间内联,而不是在 View 渲染时间期间内联。这是问题的原因, setter/getter 在恢复 View 阶段而不是渲染响应阶段被调用。

自 JSF 1.2 以来,通过改进的 View 处理程序,可以“同步”内联纯 HTML,而不会遇到难看的问题 <f:verbatim>标签。所以不再需要了。该标签也不再有有用的用例,可能会出现一些过早的性能优化,但仍然不应该将它与表达式语言获得的动态数据结合使用。

相关问题:

关于java - f :verbatim called before form submission 内的 setter/getter ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4502465/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com