【发布时间】:2019-06-24 01:15:01
【问题描述】:
我们有复杂的 JSF 页面,由可重复的 primefaces 组件组成,例如 p:dataTable、p:tabView、ui:repeat、c:foreach、javascript 等。 该页面由两个单独的表单组成,ID 分别为 formHeader 和 formBPM 奇怪的是,执行放在 formHeader 中的 h:commandButton 会导致调用 formBPM 中的所有 getter、render 和 test 表达式。在 RestoreView 和 RenderResponse 阶段都会调用表达式。
<h:form id="formHeader" enctype="multipart/form-data;charset=UTF-8">
<h:commandButton value="Call this" type="button">
<f:ajax execute="@this" />
</h:commandButton>
</h:form>
<h:form id="formBpm">
<p:tabView...>
<p:dataTable....>
</p:dataTable>
....
</p:tabView>
</h:form>
原始页面过于复杂,被动态组件和java脚本超载。 但是我已经以简化的结构对上面的页面进行了建模并检查了日志记录
<h:form id="formHeader" enctype="multipart/form-data;charset=UTF-8">
<h:commandButton value="Call this" type="button">
<f:ajax execute="@this" />
</h:commandButton>
<h:commandButton value="Call form render form" type="button">
<f:ajax execute="@form" render="@form"/>
</h:commandButton>
<h:commandButton value="Call formBpm" type="button">
<f:ajax execute=":formBpm"/>
</h:commandButton>
<h:commandButton value="Call formBpm render formBpm" type="button">
<f:ajax execute=":formBpm" render=":formBpm"/>
</h:commandButton>
<p:outputLabel id="labelThisid" value="#{testBean.varThis}"></p:outputLabel>
</h:form>
<h:form id="formBpm">
<p:outputLabel id="labelid" value="#{testBean.var1}"></p:outputLabel>
<p:tabView id="tabViewId" >
<p:tab id="tabId1" title="#{testBean.tab1}">
</p:tab>
<p:tab id="tabId2" title="#{testBean.tab2}" rendered="#{testBean.tab2Show}">
</p:tab>
</p:tabView>
</h:form>
根据日志,在 simplified 页面上,没有在单击“调用此”时执行 getter,只有在呈现适当的表单时才会执行它们,而不是执行。此外,getter 仅在 RenderResponse 阶段被调用。 原始复杂页面上调用不适当的getter的原因可能是什么?
Primefaces 6.1 jBoss EAP 6.4 JSF Mojarra 2.1.28
【问题讨论】:
-
这可能很有趣,虽然没有说明为什么表单 A 中的交互会触发表单 B 中的内容:stackoverflow.com/questions/2090033/…
-
添加一个 jsf 生命周期调试器并检查这发生在哪个生命周期中,Restoreview 最有可能
-
感谢提议,jsf生命周期调试器已经有了。 Getter 在 RESTORE_VIEW 和 RENDER_RESPONSE 阶段都被调用。
-
我期待的是 RESTORE_VIEW(并不是我的期待是正确的,只是我的知识有限,我只是期待它)。 RENDER_RESPONSE 我没想到。这些表格周围有没有偶然的表格。
-
您可以尝试在每个 jsf 标签上创建一个带有显式 ID 的 minimal reproducible example,以便在调试时在 http 请求/响应中显示得更好吗?你的 JSF 实现和版本是什么?还有PF那个?当页面中不使用 PrimeFaces 元素或根本不使用 PF 时,它是否有效?
标签: performance jsf primefaces