Note that there are some explanatory texts on larger screens.

plurals
  1. POAJAX listener not being fired for <p:selectBooleanButton> inside <p:dataList>
    primarykey
    data
    text
    <p>I am trying implement an "Add item to Cart" functionality for alist f items displayed on page using <code>&lt;p:dataList&gt;</code>. The add button is a <a href="http://www.primefaces.org/showcase/ui/selectBooleanButton.jsf" rel="nofollow">p:selectBooleanButton</a>.</p> <p>I have attached an ajax listener to the button to add current item to a collection in my backing bean. However, the listener method is not being invoked but the button rendering updates. </p> <p>Attaching a <code>valueChangeListener</code> works but I assume I should not be using it?</p> <p><strong>However, in either case my pagination stops working. Clicking on any of the pagination buttons does not change the page content.</strong></p> <p>Could someone please assist with the same or suggest a better approach?</p> <p>Following is the code:</p> <p><strong>Backing Bean</strong></p> <pre><code>@ManagedBean(name = "movies") @ViewScoped public class MovieListBean extends BaseBean implements Serializable { private static final long serialVersionUID = -1887386711644123475L; private LazyDataModel&lt;Movie&gt; lazyModel; private Map&lt;Integer, Rental&gt; cart; @PostConstruct public void initialize() { cart = new HashMap&lt;&gt;(0); } public LazyDataModel&lt;Movie&gt; getLazyModel() { if (lazyModel == null) { lazyModel = new LazyDataModel&lt;Movie&gt;() { private static final long serialVersionUID = -858683609299266223L; @Override public List&lt;Movie&gt; load(int first, int pageSize, String sortField, SortOrder sortOrder, Map&lt;String, String&gt; filters) { List&lt;Movie&gt; movieList = serviceLocator.getMovieService().getMovieCatalogInRange(first, (first + pageSize)); this.setRowCount(serviceLocator.getMovieService().getCatalogSize()); return movieList; } }; } return lazyModel; } public void updateCart(Object obj) { System.out.println("Selected Movie ID" + obj); if (lazyModel != null) { System.out.println("Selected row in datalist - " + lazyModel.getRowIndex()); System.out.println("Object instance associated with selected row - " + lazyModel.getRowData()); } // Process object instance and add to cart } public Map&lt;Integer, Rental&gt; getCart() { return cart; } public void setCart(Map&lt;Integer, Rental&gt; cart) { this.cart = cart; } } </code></pre> <p><strong>index.xhtml</strong></p> <pre><code>&lt;ui:composition template="/WEB-INF/templates/template.xhtml"&gt; &lt;ui:define name="content"&gt; &lt;h:outputStylesheet name="movies.css" library="styles" /&gt; &lt;h:form prependId="false" id="form"&gt; &lt;p:dataList value="#{movies.lazyModel}" var="movie" id="movies" paginator="true" rows="10" paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" type="none" paginatorAlwaysVisible="false" lazy="true"&gt; &lt;p:panel id="movieInfo"&gt; &lt;h:outputText value="#{movie.movieName}" styleClass="titles" /&gt; &lt;div id="infoContainer"&gt; &lt;div&gt; &lt;h:graphicImage library="images" name="#{movie.imageUri}" /&gt; &lt;/div&gt; &lt;div&gt; &lt;div&gt; &lt;h:outputText value="#{movie.plotLine}" /&gt; &lt;/div&gt; &lt;div class="rating"&gt; &lt;span&gt;Rating : &lt;/span&gt; &lt;p:rating value="#{movie.rating}" stars="10" readonly="true" /&gt; &lt;/div&gt; &lt;div id="rent"&gt; &lt;p:selectBooleanButton offLabel="Add to Cart" onLabel="Remove from Cart" id="btnRent" value="#{not empty movies.cart[movie.movieID]}"&gt; &lt;p:ajax update="btnRent" listener="#{movies.updateCart (movie.movieID)}" event="click"/&gt; &lt;/p:selectBooleanButton&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/p:panel&gt; &lt;/p:dataList&gt; &lt;/h:form&gt; &lt;/ui:define&gt; &lt;/ui:composition&gt; </code></pre> <p>I am using JSF 2.1 (Mojarra) + Primefaces 3.5</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload