Conversation Bug?
gersonk Jan 22, 2008 12:30 PMMy seam application list all books in a dataTable. The user can edit any book simply by clicking on the 'Edit This Book' button placed at the end of each row... it shows the input boxes and the save button in a modal panel.
When the user finishes updating the book information and clicks on save button, I just want to refresh the dataTable to view the changes were made. I tried using reRender, but it didn't work. For some reason, when the application starts a conversation (@Begin), the reRender does not work. How can I refresh the dataTable?
Book.java
@Name("book") @Entity public class Book{ @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Long id; private String title; private String isbn; public Book(){ } public Long getId() { return id; } public String getIsbn() { return isbn; } public void setIsbn(String isbn) { this.isbn = isbn; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; }
BookingSearchingAction.java
@Name("bookSearchAction") @Stateful public class BookSearchingAction implements BookSearching{ @Logger private Log log; @PersistenceContext(type = PersistenceContextType.EXTENDED) private EntityManager em; @DataModel private List<Book> books = new ArrayList<Book>(); @Factory(value = "books" ) public void initBooks() { books = em.createQuery("SELECT a from Book a").getResultList(); } @Remove public void destroy() {} public List<Book> getBooks() { return books; } public void setBooks(List<Book> books) { this.books = books; } }
BookEditingAction.java
@Name(value = "bookEditingAction") @Scope(ScopeType.CONVERSATION) @Stateful public class BookEditingAction implements BookEditing { @Logger private Log log; @PersistenceContext(type = PersistenceContextType.EXTENDED) private EntityManager em; @In(required = false) @Out(required = false) private Book selectedBook; @Begin() public void selectBook(Book book) { this.selectedBook = em.merge(book); } @End public void cancelSelection() { } @End public void removeBook() { em.remove(selectedBook); } @End public void saveBook() { em.merge(selectedBook); } @Remove public void destroy() {} public Book getSelectedBook() { return selectedBook; } public void setSelectedBook(Book selectedBook) { this.selectedBook = selectedBook;} }
books.xml
<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:rich="http://richfaces.org/rich" xmlns:a4j="http://richfaces.org/a4j" template="layout/template.xhtml"> <ui:define name="body"> <p>Books</p> <a4j:form> <!-- Book List --> <rich:dataTable id="bookTable" columnClasses="col" value="#{books}" var="thisBook"> <rich:column id="title"> <f:facet name="header"><h:outputText styleClass="headerText" value="Title"/></f:facet> <h:outputText value="#{thisBook.title}"/> </rich:column> <rich:column id="isbn"> <f:facet name="header"><h:outputText styleClass="headerText" value="ISBN"/></f:facet> <h:outputText value="#{thisBook.isbn}"/> </rich:column> <rich:column> <f:facet name="header"> <h:outputText styleClass="headerText" value="Operation"/> </f:facet> <a4j:commandButton value="Edit This Book" reRender="tableBookEditing" action="#{bookEditingAction.selectBook(thisBook)}" oncomplete="javascript:Richfaces.showModalPanel('editBookPanel');"/> </rich:column> </rich:dataTable> </a4j:form> <!-- Modal Panel for Editing --> <rich:modalPanel id="editBookPanel" showWhenRendered="false" height="140"> <f:facet name="header"> <h:outputText value="Edit Book"/> </f:facet> <f:facet name="controls"> <span style="cursor:pointer" onclick="javascript:Richfaces.hideModalPanel('editBookPanel')">X</span> </f:facet> <a4j:form> <rich:dataTable value="#{bookEditingAction.selectedBook}" var="sel" id="tableBookEditing"> <rich:column id="title"> <f:facet name="header"><h:outputText value="Title"/></f:facet> <h:inputText value="#{sel.title}"/> </rich:column> <rich:column id="isbn"> <f:facet name="header"><h:outputText value="ISBN"/></f:facet> <h:inputText value="#{sel.isbn}"/> </rich:column> </rich:dataTable> <a4j:commandButton value="Save" action="#{bookEditingAction.saveBook()}" oncomplete="javascript:Richfaces.hideModalPanel('editBookPanel');" reRender="bookTable"/> </a4j:form> </rich:modalPanel> </ui:define> </ui:composition>