001: package com.salmonllc.jsp.controller;
002:
003: /////////////////////////
004: //$Archive: /SOFIA/SourceCode/com/salmonllc/jsp/controller/DetailFormController.java $
005: //$Author: Dan $
006: //$Revision: 29 $
007: //$Modtime: 6/11/03 4:28p $
008: /////////////////////////
009: import com.salmonllc.html.*;
010: import java.util.*;
011: import com.salmonllc.forms.DetailForm;
012: import com.salmonllc.forms.DetailFormListener;
013: import com.salmonllc.html.events.PageEvent;
014: import com.salmonllc.html.events.SubmitEvent;
015: import com.salmonllc.html.events.SubmitListener;
016: import com.salmonllc.jsp.JspDetailForm;
017: import com.salmonllc.sql.DataStore;
018: import com.salmonllc.util.MessageLog;
019: import com.salmonllc.properties.Props;
020:
021: import java.io.File;
022:
023: /**
024: * DetailFormController creates a detailform and binds its components to the
025: * datastore columns specified by the XML file.
026: * Creation date: (7/25/01 3:19:11 PM)
027: * @author: Deepak Agarwal
028: */
029: public class DetailFormController extends BaseDetailController
030: implements SubmitListener, DetailFormListener {
031: public com.salmonllc.jsp.JspDetailForm _mainCont;
032: private int flags = 0;
033:
034: private String _redirectURL = "";
035:
036: /**
037: * Creation date: (7/25/01 11:48:04 AM)
038: * @param form com.salmonllc.jsp.JspListForm
039: */
040: private int createFlags() {
041:
042: if (_mainCont.getDeleteButton() == null
043: || _mainCont.getDeleteButton().equals(""))
044: flags |= DetailForm.INIT_NO_DELETE_BUTTON;
045:
046: if (_mainCont.getSaveButton() == null
047: || _mainCont.getSaveButton().equals(""))
048: flags |= DetailForm.INIT_NO_SAVE_BUTTON;
049:
050: if (_mainCont.getCancelButton() == null
051: || _mainCont.getCancelButton().equals(""))
052: flags |= DetailForm.INIT_NO_CANCEL_BUTTON;
053: return flags;
054: }
055:
056: /**
057: * Creation date: (7/25/01 3:16:15 PM)
058: */
059: private void defineView() throws java.sql.SQLException,
060: com.salmonllc.sql.DataStoreException {
061:
062: String datadefinition = _mainCont.getDataDictionary();
063:
064: String caption = _mainCont.getCaption();
065: if (getParameter("caption") != null)
066: caption = getParameter("caption");
067:
068: if (getParameter("datadef") != null)
069: datadefinition = getParameter("datadef");
070:
071: if (getParameter("redirect") != null)
072: _redirectURL = getParameter("redirect");
073:
074: if (getParameter("NavBarId") != null)
075: _redirectURL += "&NavBarId=" + getParameter("NavBarId");
076:
077: if (caption != null)
078: _redirectURL += "&caption=" + caption;
079:
080: String xmlPath = getPageProperties().getProperty(
081: Props.XML_DATA_PATH);
082: if (xmlPath != null && !xmlPath.endsWith(File.separator))
083: xmlPath += File.separator;
084:
085: System.out.println(" Detail Form XML Path :" + xmlPath);
086: datadefinition = xmlPath + datadefinition;
087:
088: _ds = (DataStore) this .getDataSource("dsMain");
089: if (_ds == null)
090: _ds = new DataStore(getApplicationName());
091:
092: _ds.setUseBindForUpdate(true);
093:
094: if (_detailForm != null) {
095: removePageListener(_detailForm);
096: }
097:
098: _detailForm = new DetailForm(this , _ds, createFlags());
099:
100: _detailForm.setHeadingCaption(caption);
101:
102: FormBinder binder = new FormBinder(datadefinition);
103: _detailForm = binder.bindDetailForm(_detailForm, this );
104:
105: _detailForm.addListener(this );
106:
107: replaceComponent(_mainCont.getName(), _detailForm);
108:
109: }
110:
111: /**
112: * This method was created in VisualAge.
113: */
114: public void initialize() throws Exception {
115: try {
116: super .initialize();
117: addPageListener(this );
118:
119: // Assigning to main cont
120: Enumeration e = getComponentTable().elements();
121: while (e.hasMoreElements()) {
122: HtmlComponent comp = (HtmlComponent) e.nextElement();
123: if (comp instanceof JspDetailForm) {
124: _mainCont = (JspDetailForm) comp;
125: break;
126: }
127: }
128:
129: } catch (Exception e) {
130: MessageLog.writeErrorMessage("initialize", e, this );
131: }
132: }
133:
134: /**
135: * Creation date: (8/30/01 2:00:07 PM)
136: * @return java.lang.String
137: * @param dsDataType int
138: */
139: protected String mapDataType(int dsDataType) {
140:
141: switch (dsDataType) {
142: case 0:
143: return "String";
144: case 1:
145: return "Integer";
146: case 2:
147: return "Datetime";
148: case 3:
149: return "Double";
150: case 4:
151: return "ByteArray";
152: case 5:
153: return "Short";
154: case 6:
155: return "Long";
156: case 7:
157: return "Float";
158: case 8:
159: return "Date";
160: case 9:
161: return "Time";
162: case 99:
163: return "String";
164: }
165:
166: return null;
167: }
168:
169: /**
170: * This method MUST be OVERRIDDEN in descendant classes to prohibit or restrict
171: * access to a page or some of its components.
172: * @return boolean
173: */
174: public boolean pageAccess() {
175: return true;
176: }
177:
178: /**
179: * Called after Save button is processed on Detail page.
180: * @return boolean True if continue to save, else do not continue.
181: */
182: public boolean postDetailSave() throws java.lang.Exception {
183: if (_redirectURL != null)
184: this .getCurrentResponse().sendRedirect(_redirectURL);
185: return true;
186: }
187:
188: /**
189: * Called after Save button is processed on Detail page.
190: * @return boolean True if continue to save, else do not continue.
191: */
192: public boolean preDetailDelete() throws java.lang.Exception {
193: if (_redirectURL != null)
194: this .getCurrentResponse().sendRedirect(_redirectURL);
195: return true;
196: }
197:
198: /**
199: * This method is overridden in the descendant class/page. It is used each time a user re-visits a page after the initial page generation by the initPage and createPage methods.
200: * @param p PageEvent
201: * @throws Exception
202: */
203:
204: public void request(PageEvent p) throws Exception {
205: super .request(p);
206: if (!isReferredByCurrentPage()) {
207: defineView();
208: }
209: }
210:
211: /**
212: * This method is overridden in the descendant class/page. It is used each time a user re-visits a page after the initial page generation by the initPage and createPage methods.
213: * @param p PageEvent
214: * @throws Exception
215: */
216:
217: public boolean submitPerformed(SubmitEvent p) throws Exception {
218: return true;
219: }
220:
221: public String getRedirectURL() {
222: return _redirectURL;
223: }
224: }
|