Gondim
Gondim

Reputation: 3048

CommandLink is not called anymore after click on commandButton

There are a list with 100 "Favs" on it. It only shows 10 when the page loads. When I click on "Show More Favs" it shows 10 more Favs.

What's weird about it, it's after I click on Show More Favs, clicking on Remove from list, it's not calling the method in the backBean.

My backBean is ViewScoped.

<ui:repeat value="#{bean.list}" var="fav">
 <h:form>
  <h:commandLink styleClass="someStyle" title="Remove from list" action="#{bean.remove(fav.id)}"/>
 </h:form>
</ui:repeat>
<h:form>
 <h:commandButton value="Show More Favs" action="#{bean.showMore}" >
  <f:param name="moreFav" value="10" />
  <f:ajax event="action" render="@all" />
 </h:commandButton>
</h:form>

Upvotes: 0

Views: 354

Answers (1)

BalusC
BalusC

Reputation: 1108632

The culprit is the usage of multiple forms and the render="@all". If you re-render another form from inside an ajax form, the viewstate of the another form will get lost.

You need to change the code so that only the content of another form is re-rendered:

<h:form id="otherform">
 <h:panelGroup id="list">
  <ui:repeat value="#{bean.list}" var="fav">
   <h:commandLink styleClass="someStyle" title="Remove from list" action="#{bean.remove(fav.id)}"/>
  </ui:repeat>
 </h:panelGroup>
</h:form>
<h:form>
 <h:commandButton value="Show More Favs" action="#{bean.showMore}" >
  <f:param name="moreFav" value="10" />
  <f:ajax event="action" render=":otherform:list" />
 </h:commandButton>
</h:form>

Upvotes: 1

Related Questions