f:verbatim 内的 Getter 在表单提交之前调用

发布于 2024-10-08 08:36:16 字数 974 浏览 5 评论 0原文

我有以下页面:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情感失落者 2024-10-15 08:36:16

根据您自己关于此主题的答案

我删除了 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    

允许开发人员将纯 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>

然而,它们在视图构建时间期间内联,而不是在视图渲染时间期间内联。这是问题的原因,吸气剂在恢复视图阶段而不是渲染响应阶段被调用。

从 JSF 1.2 开始,通过改进的视图处理程序,可以“同步”内联纯 HTML,而不必担心难看的 标记。所以不再需要了。该标签也不再有有用的用例,可能会出现一些过早的性能优化,但仍然不应该将其与表达式语言获得的动态数据结合使用。

相关问题:

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:

时光匆匆的小流年 2024-10-15 08:36:16

将命令按钮上的立即属性设置为 true。

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

然后它将执行ApplyRequestValues阶段的方法。

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.

看海 2024-10-15 08:36:16

我删除了 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文