00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package org.openmobileis.examples.simpleappli.terminal.services;
00026
00027 import javax.servlet.http.HttpServletRequest;
00028
00029 import org.openmobileis.common.util.exception.DatabaseException;
00030 import org.openmobileis.common.util.exception.ServiceException;
00031 import org.openmobileis.examples.simpleappli.data.BaseData;
00032 import org.openmobileis.examples.simpleappli.data.FODB.FODBBaseDataFactory;
00033 import org.openmobileis.services.SimpleEditService;
00034 import org.openmobileis.services.common.ServiceManager;
00035 import org.openmobileis.services.navigation.NavigationBarService;
00036
00037 import freemarker.template.SimpleScalar;
00038 import freemarker.template.TemplateModelRoot;
00039
00050 public final class EditBaseDataService extends SimpleEditService implements NavigationBarService {
00051
00055 public EditBaseDataService() {
00056 super();
00057 }
00058
00059
00060
00061
00062 protected void fillTemplateWithSessionData(Object sessionDatas, TemplateModelRoot templateData) throws ServiceException {
00063 BaseData data = (BaseData) sessionDatas;
00064
00065 templateData.put("id", new SimpleScalar(data.getId()));
00066 templateData.put("data",new SimpleScalar(data.getData()));
00067 }
00068
00069
00070
00071
00072 protected void storeSessionObjectInDB(Object sessionDatas, HttpServletRequest req, TemplateModelRoot templateData) throws ServiceException {
00073 BaseData data = (BaseData) sessionDatas;
00074
00075
00076 if ((data.getId() == null) || (data.getId().trim().length() == 0)) {
00077 this.setInputRequestParameterError(req, "Error :Data Id must be defined.");
00078 return;
00079 }
00080
00081 try {
00082 FODBBaseDataFactory.getManager().storeBaseData(data);
00083 } catch (DatabaseException e) {
00084 throw new ServiceException(e);
00085 }
00086 }
00087
00088
00089
00090
00091 protected void fillSessionObjectWithRequestData(Object sessionDatas, HttpServletRequest req) throws ServiceException {
00092 BaseData data = (BaseData)sessionDatas;
00093
00094
00095
00096 String temp = (String)req.getParameter("id");
00097 if (temp != null) {
00098 data.setId(temp);
00099 }
00100 temp = (String)req.getParameter("data");
00101 if (temp != null) {
00102 data.setData(temp);
00103 }
00104 }
00105
00106
00107
00108
00109 protected String getSessionDatasName() {
00110 return "basedata";
00111 }
00112
00113
00114
00115
00116 protected String getTemplateName() {
00117 return "appli/editdata.htm";
00118 }
00119
00125 protected Object createSessionObject(HttpServletRequest req) throws ServiceException {
00126
00127
00128 String idData = (String)req.getParameter("id");
00129 BaseData data = null;
00130 if (idData !=null) {
00131 try {
00132 data = FODBBaseDataFactory.getManager().getBaseData(idData);
00133 } catch (DatabaseException ex) {
00134 throw new ServiceException(ex);
00135 }
00136 }
00137 if (data == null) {
00138 data = new BaseData();
00139 }
00140 return data;
00141 }
00142
00147 protected String getDisplayServiceURI() {
00148 return "/basedata/showall";
00149 }
00150
00151 public String getServiceUri() {
00152 return ServiceManager.getManager().getServiceBaseURI() + "/basedata/edit";
00153 }
00154
00155
00156
00157
00158 public String getNavigationBarLabel(HttpServletRequest req) {
00159 return "Edit";
00160 }
00161
00162 public boolean displayFormExitMessage() {
00163 return true;
00164 }
00165
00166 public boolean displayRecursive() {
00167 return false;
00168 }
00169
00170 }