问题
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