commandButton 中的方法 editBook() 没有被调用,我不明白为什么。主要问题是在模态对话框中编辑 dataTable。任何帮助都会很棒。这是我的代码。
索引.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>
我究竟做错了什么?
编辑:
编辑书:
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);
}
索引.xhtml:
<p:commandButton
process="display"
actionListener="#{booksManager.editBook(e)}"
value="Save"
update=":form:table :form:dialog"
oncomplete="dialog:bookDialog.hide()"/>
还是不行。将事件传递给方法editBook()可能有问题吗?