001:package com.salmonllc.jsp.controller;
002:
003://///////////////////////
004://$Archive: /sofia/sourcecode/com/salmonllc/jsp/controller/ListFormController.java $
005://$Author: Tezgiden $
006://$Revision: 40 $
007://$Modtime: 9/29/03 1:54p $
008://///////////////////////
009:import java.util.*;
010:import java.io.File;
011:
012:import com.salmonllc.forms.ListForm;
013:import com.salmonllc.forms.ListFormListener;
014:import com.salmonllc.html.*;
015:import com.salmonllc.html.events.PageEvent;
016:import com.salmonllc.html.events.SubmitEvent;
017:import com.salmonllc.html.events.SubmitListener;
018:import com.salmonllc.jsp.JspListForm;
019:import com.salmonllc.sql.DataStore;
020:import com.salmonllc.util.MessageLog;
021:import com.salmonllc.properties.Props;
022:
023:/**
024: * ListFormController is used as a Special Controller to generate standard ListForms.
025: * This Controller creates the ListForm and binds all the column cells to the datastore by reading a XML file.
026: * This can be extended to do any other job or to modify any of the component specified in ListForm.
027: * Creation date: (7/20/01 3:20:08 PM)
028: * @author Administrator
029: */
030:public class ListFormController extends BaseListController implements ListFormListener, SubmitListener
031:{
032: public boolean searchButton = false;
033: public boolean addButton = false;
034: public boolean advanceSearch = false;
035: int flags = 0;
036:
037: /**
038: * Creation date: (7/25/01 11:48:04 AM)
039: */
040: private int createFlagsForListForm(int flags)
041: {
042: if(_mainCont.getButtons() == null || _mainCont.getButtons().trim().equals(""))
043: {
044: return flags;
045: }
046:
047: java.util.StringTokenizer st = new java.util.StringTokenizer(_mainCont.getButtons(), "|");
048:
049: while( st.hasMoreElements()) {
050:
051: String token = st.nextToken();
052:
053: if(token.equalsIgnoreCase("ADD"))
054: {
055: addButton = true;
056: continue;
057: }
058: if(token.equalsIgnoreCase("SEARCH"))
059: {
060: searchButton = true;
061: continue;
062: }
063:
064: if(token.equalsIgnoreCase("ADVANCE_SEARCH") || token.equalsIgnoreCase("ADVANCE") || token.equalsIgnoreCase("ASEARCH"))
065: {
066: advanceSearch = true;
067: continue;
068: }
069:
070: }
071:
072: if(!addButton)
073: flags |= ListForm.INIT_NO_ADD_BUTTON;
074:
075: if(!searchButton)
076: flags |= ListForm.INIT_NO_SEARCH_BUTTON;
077:
078: if(advanceSearch)
079: flags |= ListForm.INIT_ADVANCED_SEARCH_ON_SIDE;
080:
081: return flags;
082:
083: }
084:
085: /**
086: * Recreate the view from the xml definition in the list form and/or URL line params
087: */
088: public void defineView() throws java.sql.SQLException, com.salmonllc.sql.DataStoreException {
089:
090: String datadefinition = _mainCont.getDataDictionary();
091: String caption = getParameter("caption");
092: String navBarId = getParameter("NavBarId");
093:
094: if (getParameter("datadef") != null)
095: datadefinition = getParameter("datadef");
096:
097: querystring = "datadef=" + datadefinition + "&redirect=" + getPageName() + "?datadef=" + datadefinition;
098:
099: if (caption != null)
100: querystring += "&caption=" + caption;
101:
102: if (navBarId != null)
103: querystring += "&NavBarId=" + navBarId;
104:
105: // Create the Detail Page URL
106: String detailPage = _mainCont.getDetailPageName() + "?" + querystring;
107:
108: // XML data path where XML is located
109: String xmlPath = getPageProperties().getProperty(Props.XML_DATA_PATH);
110: if (xmlPath != null && !xmlPath.endsWith(File.separator))
111: xmlPath += File.separator;
112:
113: writeMessage("XML Path is " + xmlPath);
114:
115: if (xmlPath == null)
116: writeMessage("XMLDataPath is missing from properties file");
117:
118: // Create the Total rather complete path of XML file adding the directory to datadef(XML file name)
119: String _totaldatadefinition = xmlPath + datadefinition;
120:
121: _ds = (DataStore)this .getDataSource("dsMain");
122: if( _ds == null )
123: _ds = new DataStore(getApplicationName());
124:
125:
126: // Create the List form with Detail PAge URL - This URL is used when ADD button is clicked
127: //_listForm = new ListForm(this, detailPage, _ds, createFlagsForListForm(flags, _mainCont)); This code, was using the current object
128: // as HtmlPage. In the currewnt object(this) loadProperties() was not executed. therefore, the "_useDisabledAttribute" boolean
129: //variable was always "true". that caused all dropdowns to be displayed as "disabled" vies instead of as plain "text".
130: _listForm = new ListForm(_mainCont.getPage(), detailPage, _ds, createFlagsForListForm(flags));
131:
132: if (_listForm != null) {
133: removePageListener(_listForm);
134: }
135:
136: FormBinder binder = new FormBinder(_totaldatadefinition);
137:
138: // This querystring is used when Link is clicked
139: _listForm = binder.bindListForm(_listForm, this , querystring);
140:
141: replaceComponent(_mainCont.getName(), _listForm);
142:
143: String sSearchString = getParameter(HtmlLookUpComponent.PARAM_LISTFORM_SEARCH_FILTER_STRING);
144: String sSearchCoulmn = getParameter("searchColumn");
145:
146:
147: _linkComponents = new Vector();
148: Enumeration enum = _listForm.getComponents();
149: storeListFormLinkComponents(enum);
150:
151: if(sSearchCoulmn!=null && sSearchCoulmn.length()>0 && sSearchString !=null && sSearchString.length()>0){
152: enum = _listForm.getComponents();
153: HtmlComponent comp = getComponent(sSearchCoulmn);
154: if(comp instanceof HtmlFormComponent)
155: ((HtmlFormComponent)comp).setValue(sSearchString);
156: }
157: //get the data
158: _listForm.doRetrieve();
159: _ds.gotoFirst();
160:
161: }
162: private void storeListFormLinkComponents(Enumeration enum)
163: {
164: while(enum.hasMoreElements())
165: {
166: HtmlComponent comp = (HtmlComponent)(enum.nextElement());
167: if (comp instanceof HtmlLink)
168: _linkComponents.add(comp);
169: if(comp instanceof HtmlContainer)
170: storeListFormLinkComponents(((HtmlContainer)comp).getComponents());
171: }
172: }
173:
174: /**
175: * This method was created in VisualAge.
176: */
177: public void initialize() throws Exception
178: {
179: try
180: {
181: super .initialize();
182:
183: addPageListener(this );
184:
185: // Assigning to main cont
186: Enumeration e = getComponentTable().elements();
187: while (e.hasMoreElements())
188: {
189: HtmlComponent comp = (HtmlComponent) e.nextElement();
190: if (comp instanceof JspListForm)
191: {
192: _mainCont = (JspListForm) comp;
193: break;
194: }
195: }
196:
197: }
198: catch (Exception e)
199: {
200: MessageLog.writeErrorMessage("initialize", e, this );
201: }
202: }
203: /**
204: * This method MUST be OVERRIDDEN in descendant classes to prohibit or restrict
205: * access to a page or some of its components.
206: * @return boolean
207: */
208: public boolean pageAccess() {
209: return true;
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 void request(PageEvent p) throws Exception
218: {
219: if(!isReferredByCurrentPage())
220: defineView();
221:
222: // Set the primary Link after defining the view
223: super .request(p);
224: }
225: /**
226: * 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.
227: * @param p PageEvent
228: * @throws Exception
229: */
230:
231: public boolean submitPerformed(SubmitEvent p) throws Exception
232: {
233: return false;
234: }
235:}
|