部分呈现多余的方法调用多余、部分、方法

2023-09-10 19:36:07 作者:稀有man※

据我所知,JSF可以调用托管bean方法的几次,但如果在.xhtml调用一次。据我所知,是由于EN code *的方法。

I am aware that JSF may call a managed bean method a couple of times even if it is called only once in .xhtml. I understand that is due to encode* methods.

我想请你解释一下下面的案例给我。 我有一个JSF文件之类的,看起来是这样的:

I would like to ask you to explain the following case to me. I have a JSF file that sort of looks like this:

<h:form id="form1">
    <h:panelGroup id="output">
        ...
        <h:commandLink...>
            <f:ajax render=":form1:output"/>
        </h:commandLink>
    </h:panelGroup>
</h:form>

全部清除为止; pressing命令链路重新呈现页面的形式panelGroup中内的一部分。 在code如下:

All clear so far; pressing the command link rerenders a part of the page within the form panelGroup. The code follows:

<ui:repeat value="#{movieBean.categories}" var="category">
    <li>
        <h:outputLink value="index.xhtml">
            <f:param name="categoryId" value="#{category.categoryId}"/>
            <h:outputText value="#{category.description}"/>
        </h:outputLink>
    </li>
</ui:repeat>

#{movieBean.categories} //this is just a 'test line'

movieBean是请求范围。

movieBean is request scoped.

现在,当我进入页面的第一次,我得到两个调用movieBean.categories。 这是明显的,因为它是在code叫了两声。然而,当我打了AJAX的链接呈现 重复&GT; 又打电话甚至:UI;页面(输出),我从&LT movieBean.categories中的一部分 虽是局部呈现的页面区域之外。 测试线不叫这个时候。

Now, when I enter the page for the first time I get two calls to movieBean.categories. That is clear because it is called twice in the code. However, when I hit the AJAX link rendering only a part of the page (output) I get movieBean.categories from <ui:repeat> called again even though it is outside the partially rendered page area. The 'test line' is not called this time.

我进行的另一项测试。我删除了&LT; UI:重复&GT; 标签离开检测线而已。 AJAX部分呈现忽略了最低位为之前调用它。

I performed another test. I deleted the <ui:repeat> tag leaving the 'test line' only. AJAX partial rendering dosen't call it as before.

是什么让movieBean.categories一个&LT内部调用; UI:重复&GT; 标记不同 比在测试线?为什么是在&LT通话; UI:重复&GT; 时作出pressing的AJAX链接 即使它是外部分呈现&LT; H:panelGroup中的id =输出/&GT; 标签?

What makes the movieBean.categories call inside a <ui:repeat> tag different than the one in 'test line'? And why is the call inside <ui:repeat> made when pressing the AJAX link even though it is outside partially rendered <h:panelGroup id="output"/> tag?

推荐答案

我是pretty的确保多余的呼叫一个阶段时,JSF重建元素树来存储P​​OST数据到相应的元素中进行。

I'm pretty sure that "redundant" call is made within a phase where JSF rebuilds element tree to store POST data into appropriate elements.

所以你基本上每个请求两种吸气电话,如果你留在页面上。第一个存储新形式的值,然后渲染页面内容。

So you basically have two getter calls per request if you stay on the page. First one to store new form values, then to render page content.