Begin(nested=true,flushMode=MANUAL) persists without flush()
jakec Jun 26, 2008 9:10 PMI am starting a nested conversation with flushMode=MANUAL and editing within a modalPanel. When someone enters invalid information, I keep the modalPanel up and attempt to show an error message (error messages not working, posted in another thread), and do NOT flush() to the DB. However, my dataDetails div is still reRendered under the modalPanel (expected), and shows that the info is changed anyway (unexpected). If I then abandon the changes, the bad data is still in the DB.
Isn't flushMode=MANUAL supposed to prevent anything getting flushed to the DB? How do I get this to work correctly?
main.xhtml
<ui:composition xmlns=...> <ui:define name="body"> <a:include viewId="modal.txml"/> .... <h:form id="infoForm"> <a:commandLink id="editInfo" value="Edit Info" action="#{myBean.editInfo(currentInfo)}" oncomplete="Richfaces.showModalPanel('modalPanel');" reRender="modalPanelDiv"/> </h:form> </ui:define> </ui:composition>
modal.txml
<ui:composition xmlns=...> <rich:modalPanel id="modalPanel" autosized="true" zindex="2000"> <h:form id="editForm"> <s:validateAll> <s:div id="modalPanelDiv"> <s:decorate id="nameDecor" template="edit.txml"> <ui:define name="label">Name:</ui:define> <h:inputText id="name" value="#{myBean.name}"/> </s:decorate> <a:commandButton id="abandon" image="/img/button/abandon.gif" action="#{myBean.abandonEdits}" title="Abandon Changes" oncomplete="if(#{myBean.closingModalWindow}) Richfaces.hideModalPanel('modalPanel'); return false;"/> <a:commandButton id="submit" image="/img/button/done.gif" action="#{myBean.commitEdits}" title="Commit Changes" oncomplete="if(#{myBean.closingModalWindow}) Richfaces.hideModalPanel('modalPanel'); return false;" reRender="dataTable,dataDetails"/> </s:div> </s:validateAll> </h:form> </rich:modalPanel> </ui:composition>
MyBeanBean.java
... @Begin(nested = true, flushMode = FlushModeType.MANUAL) public void editInfo(Info i) { info = entityManager.merge(i); editingInfo = true; closingModalWindow = false; } public void commitEdits() { closingModalWindow = true; if(// Detect invalid entry//) { facesMessages.addToControlFromResourceBundle("name", "nameValidationError"); closingModalWindow = false; return; } if (!entityManager.contains(info)) entityManager.persist(info); entityManager.flush(); info = entityManager.find(Info.class, info.getId()); closingModalWindow = true; Conversation.instance().endBeforeRedirect(); } public void abandonEdits() { if (entityManager.contains(info)) { entityManager.refresh(info); info = entityManager.find(Info.class, info.getId()); } closingModalWindow = true; Conversation.instance().endBeforeRedirect(); return; } ...