设置:我有2种形式A&B我有一个commandLink窗体A:
<h:commandLink actionListener="#{homeView.selectDiv('homeUpdates')}">#{msg.homeUpdates}
<f:ajax render=":B" execute="@this" />
</h:commandLink>
......这些更新的形式B.
问题是,当我点击了ajax链接,它将重建形成A以及从一个UI获得一个例外:重复我。 这是正确的行为? 如果它重建形式的呢?
我使用JSF 2.2和形式A包含的UI:片段=> UI:包括=> UI:重复
=====新增SSCCE =======下面的代码不按更新B之后跑! 两次。 它提供了重复ID的异常。 对于UI的价值:重复无关
<h:head>
</h:head>
<h:body>
<h:form id="A">
<ul class="tableView notification">
<ui:repeat var="notification" value="#{dashboardBean.notifications}">
<li>
xx
</li>
</ui:repeat>
</ul>
<h:commandLink value="Update B!" listener="#{dashboardBean.toggleRendered}">
<f:ajax execute="@this" render=":B" />
</h:commandLink>
</h:form>
<h:form id="B">
</h:form>
</h:body>
在初始请求的视图创建后 ,在回发的视图被恢复。 背诵一些点JSF 2.2规范的透明度(重点煤矿):
P. 2.2.1:
如果请求不是回发...呼吁的ViewHandler CreateView的()。 如果请求是回发,...调用的ViewHandler。 restoreView(),传递FacesContext实例当前请求和视图识别符,并返回一个UIViewRoot为还原的图。
P. 2.5.8:
在JSF视图中选择组件可以priocessed(称为部分处理)和选定的部件可以被呈现给客户端(称为部分渲染)。
P. 13.4:
JSF的生命周期,可以被看作是一个由执行阶段和一个呈现阶段的。 局部遍历是可用于在视图中“访问”一个或多个组件,这可能有他们穿过“执行”和/或“渲染”请求处理生命周期的相位的技术。
当您使用AJAX, PartialViewContext
类将包含对穿越恢复视图所需要的全部信息。
因此,要回到你的问题,根据<f:ajax render=":B" execute="@this" />
设置, 只与形式id="B"
将被重新描绘 ,这意味着<h:form id="B">
,没有形式嵌套等
关于你提到的“不工作”的评论简单的测试用例与平面图范围内管理豆给了我预期的结果:
<h:form id="A" >
<h:outputText value="#{twoFormsBean.a}"/>
<h:commandLink actionListener="#{twoFormsBean.actionA}">
Update B!
<f:ajax execute="@this" render=":B"/>
</h:commandLink>
</h:form>
<h:form id="B" >
<h:outputText value="#{twoFormsBean.b}"/>
<h:commandLink>
Update Both!
<f:ajax execute="@this" render=":A :B"/>
</h:commandLink>
</h:form>
同
@ManagedBean
@ViewScoped
public class TwoFormsBean implements Serializable {
private String a = "A";//getter
private String b = "B";//getter
public void actionA(ActionEvent ae) {
a = "newA";
b = "newB";
}
}
文章来源: Does Facelets rebuild the whole page if Ajax is trigger from a form and updates another?