001: package com.salmonllc.examples.example8;
002:
003: //The Salmon Open Framework for Internet Applications (SOFIA)
004: //Copyright (C) 1999 - 2002, Salmon LLC
005: //
006: //This program is free software; you can redistribute it and/or
007: //modify it under the terms of the GNU General Public License version 2
008: //as published by the Free Software Foundation;
009: //
010: //This program is distributed in the hope that it will be useful,
011: //but WITHOUT ANY WARRANTY; without even the implied warranty of
012: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: //GNU General Public License for more details.
014: //
015: //You should have received a copy of the GNU General Public License
016: //along with this program; if not, write to the Free Software
017: //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018: //
019: //For more information please visit http://www.salmonllc.com
020:
021: import com.salmonllc.jsp.*;
022: import com.salmonllc.examples.SiteMapConstants;
023: import com.salmonllc.html.events.*;
024: import com.salmonllc.util.MessageLog;
025:
026: /**
027: * This class is the controller for the contact list page.
028: */
029: public class ContactListController extends JspController implements
030: SubmitListener, PageListener {
031:
032: //Visual Components
033: public com.salmonllc.html.HtmlSubmitButton _add;
034: public com.salmonllc.html.HtmlSubmitButton _search;
035: public com.salmonllc.html.HtmlTextEdit _eMail;
036: public com.salmonllc.html.HtmlTextEdit _firstName;
037: public com.salmonllc.html.HtmlTextEdit _lastName;
038:
039: //DataSources
040: public com.salmonllc.examples.example8.ContactModel _dsContact;
041: public com.salmonllc.examples.example8.ContactQBE _qbeContact;
042:
043: public void initialize() {
044: //add te listeners
045: addPageListener(this );
046: _add.addSubmitListener(this );
047: _search.addSubmitListener(this );
048:
049: //initially load all the contacts
050: search();
051: }
052:
053: /**
054: * This method get fired when the user clicks a button
055: */
056: public boolean submitPerformed(SubmitEvent e) throws Exception {
057: if (e.getSource() == _search) {
058: search();
059: scrollToItem("scrollToMe");
060: } else if (e.getSource() == _add)
061: gotoSiteMapPage(SiteMapConstants.DETAIL_DATA_ENTRY);
062: return true;
063: }
064:
065: /**
066: * This method seaches the database with whatever criteria were specified.
067: * If no criteria are specified it will try to retrieve all the contacts.
068: */
069: private void search() {
070: try {
071: _dsContact.retrieve(_qbeContact);
072: } catch (Exception e) {
073: MessageLog.writeErrorMessage("search", e, this );
074: }
075: }
076:
077: /**
078: * This event will get fired each time a page is requested by the browser before any HTML is generated.
079: */
080: public void pageRequested(PageEvent p) throws Exception {
081: //check for a parameter, reload. If it is there, we want to reload all the rows in the list,
082: //but only if the request didn't come from this page.
083: if (!isReferredByCurrentPage()) {
084: if (getParameter("reload") != null)
085: search();
086: }
087: }
088:
089: /**
090: * This event is used to fill out the PageListener intrface, but isn't used in this controller.
091: */
092: public void pageRequestEnd(PageEvent p) throws Exception {
093: }
094:
095: /**
096: * This event is used to fill out the PageListener intrface, but isn't used in this controller.
097: */
098: public void pageSubmitEnd(PageEvent p) {
099: }
100:
101: /**
102: * This event is used to fill out the PageListener intrface, but isn't used in this controller.
103: */
104: public void pageSubmitted(PageEvent p) {
105: }
106: }
|