Ajax调用JSF-2.0后Commandlink行动不起作用 [英] Commandlink action does not work after an ajax call JSF-2.0
问题描述
在commandlink链接2没有下班后一个Ajax调用,以使面板组PANEL1。这是当整个页面被relaoded而不是Ajax调用显示模式工作。
Main.xhtml
< H:panelGroup中的id =PANEL1>
< UI:片段渲染=#{downloadTo.showModal}>
<用户界面:包括SRC =modal.xhtml/>
< / UI:片断>
< /小时:panelGroup中>
< H:形式GT;
< H:commandLink ID =链接值=下载行动=#{backing.openModal()}>
< F:AJAX渲染=_ PANEL1/>
< / H:commandLink>
< /小时:形式GT;
modal.xhtml包含
< H:形式GT;
< H:commandLink ID =链接2值=下载行动=#{backing.downloadData()}/>
< /小时:形式GT;
您需要确保支持bean持有的渲染
属性的条件 @ViewScoped
。否则病情会被初始化为默认的Ajax请求。您还需要修改< F:AJAX>
渲染明确包括任何其他的客户端ID < H:形式GT;
这是Ajax的更新,否则就会失去它的视图状态。
例如。在 modal.xhtml
< H:格式ID =downloadForm>
< H:commandLink ID =链接2值=下载行动=#{backing.downloadData()}/>
< /小时:形式GT;
这种变化在 main.xhtml
< H:形式GT;
< H:commandLink ID =链接值=下载行动=#{backing.openModal()}>
< F:AJAX渲染=_ PANEL1 _downloadForm/>
< / H:commandLink>
< /小时:形式GT;
参见:
- <一个href="http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html#AjaxRenderingOfContentWhichContainsAnotherForm"相对=nofollow>在JSF 2.0通信 - 内容的Ajax渲染包含另一种形式
The commandlink link2 does not have work after an ajax call is made to render a panel group panel1. This was working when the whole page was relaoded instead of ajax call to display the modal.
Main.xhtml
<h:panelGroup id="panel1">
<ui:fragment rendered="#{downloadTo.showModal}">
<ui:include src="modal.xhtml" />
</ui:fragment>
</h:panelGroup>
<h:form>
<h:commandLink id="link" value="download" action="#{backing.openModal()}">
<f:ajax render="_panel1"/>
</h:commandLink>
</h:form>
modal.xhtml contains
<h:form>
<h:commandLink id="link2" value="download" action="#{backing.downloadData()}"/>
</h:form>
You need to make sure that the backing bean holding the condition for the rendered
attribute is @ViewScoped
. Otherwise the condition will be reinitialized to default on the ajax request. You also need to change the <f:ajax>
render to explicitly include the client ID of any other <h:form>
which is to be ajax-updated, otherwise it will lose its view state.
E.g. in modal.xhtml
<h:form id="downloadForm">
<h:commandLink id="link2" value="download" action="#{backing.downloadData()}"/>
</h:form>
with this change in main.xhtml
<h:form>
<h:commandLink id="link" value="download" action="#{backing.openModal()}">
<f:ajax render="_panel1 _downloadForm" />
</h:commandLink>
</h:form>
See also:
这篇关于Ajax调用JSF-2.0后Commandlink行动不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!