0

Method editBook() in commandButton is not called and i cant understand why.The main issue is to make edition of dataTable in modal dialog. Any help would be great. This is my code.

index.xhtml :

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.org/ui">
<h:head>
    <title>Facelet Title</title>
</h:head>
<h:body>
    Hello from Facelets
<h:form id="form">
        <p:dataTable id="table" var="book" value="#{booksManager.booksTable.booksList}" paginator="true" rows="10"
                     rowKey="#{book.bookId}" selectionMode="single" dblClickSelect="true" selection="#{booksManager.selectedBook}"> 
            <p:ajax event="rowSelect"
                    update=":form:display"
                    oncomplete="dialog:bookDialog.show()"
                    listener="#{booksManager.prepareEdit()}"/>
            <p:column headerText="Autor"> 
                <h:outputText value="#{book.author}" /> 
            </p:column> 
            <p:column headerText="Tytuł"> 
                <h:outputText value="#{book.title}" /> 
            </p:column> 
            <p:column headerText="Data publikacji"> 
                <h:outputText value="#{book.publishingDate}" /> 
            </p:column>
        </p:dataTable>
        <h:outputText value="#{booksManager.editedBooks}" />

        <p:dialog id="dialog"
                  header="Book Detail"
                  widgetVar="bookDialog"
                  resizable="false"
                  showEffect="fade" hideEffect="explode" modal="true">

            <h:panelGrid id="display" columns="2" cellpadding="4">

                <h:outputText value="Autor:" />
                <p:inputText id="AuthorEdit"
                             value="#{booksManager.selectedBook.author}" />

                <h:outputText value="Tytuł:" />
                <p:inputText id="TitleEdit"
                             value="#{booksManager.selectedBook.title}" />

                <h:outputText value="Data publikacji:" />
                <p:inputText id="DateEdit"
                             value="#{booksManager.selectedBook.publishingDate}" />

                <p:commandButton 
                                 process="display"
                                 actionListener="#{booksManager.editBook()}"
                                 value="Save"
                                 update=":form:table :form:dialog"
                                 oncomplete="dialog:bookDialog.hide()"/>   
            </h:panelGrid>
        </p:dialog>

    </h:form>

    <h:form>
        <h:outputLabel value="E:" />
        <h:inputText value="#{booksManager.count}" />
        <h:commandButton value="P" action="#{booksManager.generateBooks()}" />
    </h:form>



</h:body>
</html>

What am i doing wrong?

EDIT:

editBook:

public void editBook(ActionEvent e) {
    System.out.println("is in");
    selectedBook.setBookId(this.selectedBookBefEdit.getBookId());
    selectedBook.setTitle(this.selectedBookBefEdit.getTitle());
    selectedBook.setAuthor(this.selectedBookBefEdit.getAuthor());
    selectedBook.setPublishingDate(this.selectedBookBefEdit.getPublishingDate());
    editedBooks++;
    System.out.println(editedBooks);
}

index.xhtml:

<p:commandButton 
      process="display"
      actionListener="#{booksManager.editBook(e)}"
      value="Save"
      update=":form:table :form:dialog"
      oncomplete="dialog:bookDialog.hide()"/> 

Still does not work. Maybe is something wrong with passing event to method editBook()?

demageron
  • 23
  • 1
  • 2
  • 7

2 Answers2

3

Make sure you use the following package in your method :

   javax.faces.event.ActionEvent

If it is still not working Look at here, commandButton/commandLink/ajax action/listener method not invoked or input value not updated

Community
  • 1
  • 1
Rollyng
  • 1,387
  • 2
  • 12
  • 18
2

Your actionListener EL expression does not match the method signature with the ActionEvent argument. If you intend to let JSF set and pass the default ActionEvent argument, then you should not be using any parenthesis in the expression.

Your initial attempt

actionListener="#{booksManager.editBook()}"

and your second attempt

actionListener="#{booksManager.editBook(e)}"

are therefore wrong. The right way is

actionListener="#{booksManager.editBook}"

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555