简体   繁体   中英

Call of action method from iterated h:commandButton fails

I am trying to implement a function that adds a book to a shopping cart.

The Cart bean has the fields to hold the request parameters. It is session scoped.

<h:form id="addBookToCartForm">
    <ui:repeat var="book" value="#{search.bookList}">
        <h:commandButton value="#{messages.addToCart}" 
            action="#{cart.addBookToCart}">
            <f:param name="bookId" value="#{book.bookId}" />
        </h:commandButton>
    </ui:repeat>
</h:form>

The request from the view index.jsf, the action method calls the view cart.jsf.

The problem is: The action method isn't called, not even the bean itself is constructed. I had a look at solutions for similar problems but couldn't find a solution that pointed in the right direction. At first I thought #{search.bookList} could be a problem but I don't need the bookList for the next view.

Activating debugging via <ui:debug> reveals this:

java.lang.UnsupportedOperationException: Not supported. at javax.faces.component.UIViewAction.getActionListener(UIViewAction.java:249)

This message refers to the metadata at the top of index.jsf:

<f:metadata>
    <f:viewParam name="genreTypeId" value="#{search.genreTypeId}" />
    <f:viewAction action="#{search.searchByGenreTypeId}" />
</f:metadata>

The search bean is where the bookList comes from.

Update message using ajax update. It will show some validation message.

As it turns out the problem wasn't the iteration at all but the return value of the action methods my application is using. In order to keep the view instance the methods have to return either null or void.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM