设置:我有两个表单A和B我在表单A中有一个commandLink:
<h:commandLink actionListener="#{homeView.selectDiv('homeUpdates')}">#{msg.homeUpdates}
<f:ajax render=":B" execute="@this" />
</h:commandLink>
...which更新表单B。
问题是,当我单击ajax链接时,它也会重新构建表单A,并从ui获得一个异常:重复I have。这是正确的行为吗?它也应该重建form A吗?
我使用的是JSF2.2,表单A包含一个ui:fragment=>ui:include=>ui:repeat
=====Added SSCCE=======按下更新B后,以下代码不会运行!两次。它给出了一个重复id的异常。ui:repeat的值无关紧要
<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>
发布于 2013-04-26 21:30:34
在初始请求时,视图被创建为,在回发时,该视图被恢复。为了清晰起见,我要背诵JSF 2.2 specification的一些观点(强调我的观点):
P.2.2.1:
如果请求不是回发,则为
...在ViewHandler上调用createView()。如果请求是回发,...调用ViewHandler.restoreView(),,传递当前请求的FacesContext实例和视图标识符,并返回恢复的视图的UIViewRoot。
P.2.5.8
可以对JSF视图中的选定组件进行部分处理(称为部分处理),并且可以将选定的组件呈现给客户端(称为部分呈现)。
P.13.4
在JavaServer Faces生命周期中,可以将其视为由执行阶段和呈现阶段组成。部分遍历是一种技术,可用于“访问”视图中的一个或多个组件,潜在地使它们通过请求处理生命周期的“执行”和/或“呈现”阶段。
使用AJAX时,PartialViewContext
类将包含遍历恢复的视图所需的所有信息。
因此,回到您的问题,在<f:ajax render=":B" execute="@this" />
设置下,只有带有的表单将被重新呈现,这意味着<h:form id="B">
,没有表单嵌套,等等。
关于你的“不工作”的评论,简单的测试用例和一个简单的视图作用域的托管bean给了我预期的结果:
<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";
}
}
https://stackoverflow.com/questions/16234805
复制相似问题