Q:

How to solve javax.el. MethodNotFoundException

I'm trying to develop a simple CRUD operation with JSF and JPA.  I've already developed the create operation and the read operation.  Now I'm trying to implement the delete operation, but when I'm trying to delete I have this error 
 javax.el. MethodNotFoundException: /index.xhtml @54,25 action="#{book.removeBook(book)}": Method not found: it.crud.data. Book@3bc35357.removeBook(it.crud.data. Book)
javax.faces. FacesException: #{book.removeBook(book)}: javax.el. MethodNotFoundException: /index.xhtml @54,25 action="#{book.removeBook(book)}": Method not found: it.crud.data. Book@3bc35357.removeBook(it.crud.data. Book)
    at com.sun.faces.application. ActionListenerImpl.processAction(ActionListenerImpl.java:110)
    at javax.faces.component. UICommand.broadcast(UICommand.java:315)
    at javax.faces.component. UIData.broadcast(UIData.java:1108)
    at javax.faces.component. UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component. UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle. InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle. Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle. LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp. FacesServlet.service(FacesServlet.java:658)
    at org.apache.catalina.core. ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core. ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server. WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core. ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core. ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.openejb.server.httpd. EEFilter.doFilter(EEFilter.java:65)
    at org.apache.catalina.core. ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core. ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core. StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core. StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.tomee.catalina. OpenEJBValve.invoke(OpenEJBValve.java:44)
    at org.apache.catalina.authenticator. AuthenticatorBase.invoke(AuthenticatorBase.java:493)
    at org.apache.catalina.core. StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves. ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.tomee.catalina. OpenEJBSecurityListener$RequestCapturer.invoke(OpenEJBSecurityListener.java:97)
    at org.apache.catalina.valves. AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
    at org.apache.catalina.core. StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector. CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
    at org.apache.coyote. AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote. AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:800)
    at org.apache.tomcat.util.net. NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1471)
    at org.apache.tomcat.util.net. SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent. ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent. ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads. TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang. Thread.run(Thread.java:748)

Entity class:
@Entity
@Table(name="book")
public class Book {

    private Integer id_book;
    private String name;
    private String author;
    private String category;
    private String year;
    private String price;

    @Id
    @GeneratedValue(strategy=GenerationType. IDENTITY)
    @Column(name="id_book")
    public Integer getId_book() {
        return id_book;
    }
    public void setId_book(Integer id_book) {
        this.id_book = id_book;
    }

    @Column(name="name")
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    @Column(name="author")
    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }

    @Column(name="category")
    public String getCategory() {
        return category;
    }
    public void setCategory(String category) {
        this.category = category;
    }

    @Column(name="year")
    public String getYear() {
        return year;
    }
    public void setYear(String year) {
        this.year = year;
    }

    @Column(name="price")
    public String getPrice() {
        return price;
    }
    public void setPrice(String price) {
        this.price = price;
    }

}

Bean class:
@Stateless
public class BookBean implements BookLocal, BookRemote {

    @PersistenceContext(unitName="CRUDPersistence")
    private EntityManager entityManager;

    public void createBook(Book book) {
        this.entityManager.persist(book);
    }

    public List<Book> readContatti(){
        return entityManager.createQuery("SELECT b FROM Book b").getResultList();
    }

    public void deleteBook(Book book) {
        this.entityManager.remove(book);
    }
}

Managed bean:
@ManagedBean(name="book")
@RequestScoped
public class BookManagedBean implements Serializable {

    private static final long serialVersionUID = 1L;
    private Book b;

    @EJB
    private BookLocal bookBusiness;

    public BookManagedBean() {
        b = new Book();
    }

    public Book getB() {
        return b;
    }

    public void setB(Book b) {
        this.b = b;
    }

    public void storeBook() {
        bookBusiness.createBook(b);
    }

    public List<Book> getBooks(){

        return bookBusiness.readContatti();
    }

    public String removeBook(Book b) {
        bookBusiness.deleteBook(b);
        return "index.xhtml?faces-redirect=true";
    }
}

index.xhtml:
<! DOCTYPE html>
<html xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://primefaces.org/ui">
<link rel="stylesheet"
    href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous" />
<h:head>
    <title>Book</title>
</h:head>
<h:body>
    <h1>Book</h1>
    <h:form>
        <h:panelGrid columns="12" cellpadding="5">
            <h:outputText value="Name " />
            <ui:inputText value="#{book.b.name}" />
            <h:outputText value="Author " />
            <ui:inputText value="#{book.b.author}" />
            <h:outputText value="Category " />
            <ui:inputText value="#{book.b.category}" />
            <h:outputText value="Year " />
            <ui:inputText value="#{book.b.year}" />
            <h:outputText value="Price " />
            <ui:inputText value="#{book.b.price}" />
            <ui:commandButton value="Add" icon="fa fa-fw fa-plus"
                action="#{book.storeBook()}" />
        </h:panelGrid>
    </h:form>

    <h:form id="form">
        <ui:dataTable value="#{book.books}" var="book"
            style="margin: 2em;" rowKey="#{book.id}">
            <ui:column headerText="Name">
                <h:outputText value="#{book.name}" />
            </ui:column>
            <ui:column headerText="Year">
                <h:outputText value="#{book.year}" />
            </ui:column>
            <ui:column headerText="Author">
                <h:outputText value="#{book.author}" />
            </ui:column>
            <ui:column headerText="Category">
                <h:outputText value="#{book.category}" />
            </ui:column>
            <ui:column headerText="Price">
                <h:outputText value="$#{book.price}" />
            </ui:column>
            <ui:column style="width:100px;text-align: center">

                <ui:commandButton action="#{book.removeBook(book)}"
                    icon="fa fa-trash"></ui:commandButton>
            </ui:column>
        </ui:dataTable>
    </h:form>
</h:body>
</html>

Where is the problem?  Thanks! 

A:

The data table var name conflicts with your bean name, both book.  Rename either one.  For example:
@ManagedBean(name="bookBean")

<ui:commandButton action="#{bookBean.removeBook(book)}" ../>

