Commandlink action does not work after an ajax call JSF-2.0

巧了我就是萌 提交于 2019-12-24 02:00:10

问题


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>

回答1:


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:

  • Communication in JSF 2.0 - Ajax rendering of content which contains another form



回答2:


what i see is, that you are rendering _panel1 not panel1. this should work:

<h:commandLink id="link" value="download" action="#{backing.openModal()}">
    <f:ajax render="panel1"/>
 </h:commandLink> 


来源:https://stackoverflow.com/questions/9880674/commandlink-action-does-not-work-after-an-ajax-call-jsf-2-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!