Hi Guys, A new requirement has come up where I need to provide validation warnings to the end user on form submission. As long as the user clicks okay to the warning, they can continue on with the save. My current design is as followed.
1. Submit ajax form "timesheet object" 2. Handle form validation errors server side and return to errors to UI 3. If no validation errors occur, process warning logic. 4. If warnings exist, temporarily persist timesheet object to timesheetHolder obj 5. Return warnings to ui via ajax for the user to OK and acknowledge. 6. On warning submit, grab persisted timesheetHolder obj and copy property values to timesheet object. 7. Save timesheet object. Although in theory his should work, I continue to get the following hibernate exception. "a different object with the same identifier value was already associated with the session" Backend code looks something like this. warning.java @PageActivationContext @Property private TimeSheetEntity timesheet; @Persist(PersistenceConstants.FLASH) private TimeSheetEntity timeSheetHolder; @Property private WarningExample warningExample; @InjectComponent private Zone formZone, warningZone; void onActivate() { if (timesheet== null) { timesheet= new TimeSheetEntity(); } } Object onValidateFromForm() throws IllegalAccessException, InvocationTargetException { if (timesheet.getName() == null) { form.recordError("fix field"); } if (!form.getHasErrors()) { timeSheetHolder = new TimeSheetEntity(); BeanUtils.copyProperties(timeSheetHolder , timesheet); hasWarning = true; } if (hasWarning || form.getHasErrors()) { return formZone.getBody(); } return null; } @CommitAfter Object onSuccessFromForm() throws IllegalAccessException, InvocationTargetException { if (timeSheetHolder != null) { BeanUtils.copyProperties(timesheet, timeSheetHolder);; } session.saveOrUpdate(timeSheetHolder); return linkSource.createPageRenderLinkWithContext(TimeSheet.class, timesheet.getId()); } Warning form Object onValidateFromWarningForm() { if (!warningExample.hasWarning) { warningForm.recordError("Form error"); return warningZone.getBody(); } return null; } Object onSuccessFromWarningForm() throws IllegalAccessException, InvocationTargetException { return onSuccessFromForm(); } public class WarningExample { private boolean hasWarning; public boolean isHasWarning() { return hasWarning; } public void setHasWarning(boolean hasWarning) { this.hasWarning = hasWarning; } } warning.tml <html t:type="layout" title="this is a warning" xmlns:t=" http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter"> <div t:type="zone" t:id="formZone" id="formZone"> <t:form t:id="form" zone="formZone"> <t:errors/> <div class="form-group"> <t:Label class="control-label" for="warning"/> <t:TextField t:id="warning" value="warning.name"/> </div> <t:submit t:id="save" value="save"/> </t:form> <t:if test="hasWarning"> <div t:type="zone" t:id="warningZone" id="warningZone"> <t:form t:id="warningForm" zone="warningZone"> <t:errors/> <t:checkbox t:id="hasWarning" value="warningExample.hasWarning"/>Notice 1 <t:submit t:id="saveWarning" value="save warning"/> </t:form> </div> </t:if> </div> </html> Has anybody done anything like this or have a better approach? Perhaps there is a work around to my bug as well. Please let me know if anybody has a suggestions. Thanks