1 64 65 package com.jcorporate.expresso.services.controller.dbmaint; 66 67 import com.jcorporate.expresso.core.controller.ControllerException; 68 import com.jcorporate.expresso.core.controller.ControllerRequest; 69 import com.jcorporate.expresso.core.controller.ControllerResponse; 70 import com.jcorporate.expresso.core.controller.ErrorCollection; 71 import com.jcorporate.expresso.core.controller.NonHandleableException; 72 import com.jcorporate.expresso.core.controller.Output; 73 import com.jcorporate.expresso.core.dataobjects.DataObject; 74 import com.jcorporate.expresso.core.db.DBException; 75 import com.jcorporate.expresso.services.controller.ui.DefaultAutoElement; 76 import org.apache.log4j.Logger; 77 78 79 86 public class AddUpdate 87 extends UpdateBase { 88 private static Logger log = Logger.getLogger(AddUpdate.class); 89 90 93 public AddUpdate() { 94 super(); 95 } 96 97 101 public AddUpdate(String code, String descrip) { 102 super(code, descrip); 103 104 } 105 106 115 public void run(ControllerRequest req, ControllerResponse res) 116 throws ControllerException, NonHandleableException { 117 super.run(req, res); 118 119 DataObject myDBObj = this.getDataObject(); 120 ErrorCollection ee = new ErrorCollection(); 121 122 try { 123 setFormCache(); 124 125 129 myDBObj.clear(); 130 myDBObj = DefaultAutoElement.getAutoControllerElement().parseDBObject(req, myDBObj, ee); 131 if (ee.getErrorCount() > 0) { 132 if (log.isDebugEnabled()) { 133 log.debug("There were errors - transitioning back to Add state"); 134 } 135 136 res.saveErrors(ee); 137 transition("Add", req, res); 138 return; 139 } 140 141 myDBObj.add(); 142 143 144 super.saveBlobFields(myDBObj); 146 147 addOutput(new Output("title", "Data Saved.")); 148 showUserName(""); 149 addOutput(new Output("message", "Record Added")); 150 showNext = false; 151 showPrev = false; 152 showKey(true); 153 showOptions(); 154 clearFormCache(); 155 } catch (DBException de) { 156 ee.addError(de); 157 res.saveErrors(ee); 158 transition("Add", req, res); 159 return; 160 } 161 } 165 166 } 167 168 | Popular Tags |