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.sql.*;
025: import com.salmonllc.util.MessageLog;
026:
027: /**
028: * The controller for the detail portion of the Contact List/Detail data entry example
029: */
030: public class ContactDetailController extends JspController implements
031: SubmitListener, PageListener {
032:
033: //Visual Components
034: public com.salmonllc.html.HtmlSubmitButton _cancel;
035: public com.salmonllc.html.HtmlSubmitButton _delete;
036: public com.salmonllc.html.HtmlSubmitButton _save;
037: public com.salmonllc.html.HtmlValidatorText _errorMessage;
038: public com.salmonllc.jsp.JspDisplayBox _displaybox1;
039:
040: //DataSources
041: public com.salmonllc.examples.example8.ContactModel _dsContact;
042:
043: public void initialize() {
044: addPageListener(this );
045: _delete.addSubmitListener(this );
046: _save.addSubmitListener(this );
047: _cancel.addSubmitListener(this );
048: _dsContact.setAutoValidate(false);
049:
050: }
051:
052: /**
053: * Event is fired when one of the buttons is clicked
054: */
055: public boolean submitPerformed(SubmitEvent e) throws Exception {
056: if (e.getSource() == _delete) {
057: // This deletes the current row in the DataStore.
058: // This will generate a delete statment that will remove the row from the database when the update method is called.
059: if (_dsContact.getContactContactId() > -1) {
060: _dsContact.deleteRow();
061: _dsContact.update();
062: }
063: gotoSiteMapPage(SiteMapConstants.LIST_DETAIL_DATA_ENTRY,
064: "?reload=true");
065: } else if (e.getSource() == _save) {
066: // This method will cause the database to reflect the changes made in the datastore.
067: // All transaction operations are handled within the datastore.
068: try {
069: _dsContact.update();
070: gotoSiteMapPage(
071: SiteMapConstants.LIST_DETAIL_DATA_ENTRY,
072: "?reload=true");
073: } catch (DataStoreException ex) {
074: _errorMessage
075: .addErrorMessage("A database error occured saving your changes.");
076: MessageLog.writeErrorMessage("submitPerformed", ex,
077: this );
078: }
079: } else if (e.getSource() == _cancel) {
080: //just return to the detail page and don't do anything
081: gotoSiteMapPage(SiteMapConstants.LIST_DETAIL_DATA_ENTRY);
082: }
083:
084: return true;
085: }
086:
087: /**
088: * Event is fired each time the page is requested
089: */
090: public void pageRequested(PageEvent p) throws Exception {
091: //check the contact_id parameter
092: //if the parameter is not passed in, just put the page in "add mode"
093: //else retrieve the row
094:
095: if (!isReferredByCurrentPage()) {
096: String id = getParameter("contact_id");
097: if (id == null) {
098: _dsContact.reset();
099: _dsContact.insertRow();
100: } else {
101: _dsContact.retrieve("contact_id=" + id);
102: if (_dsContact.getRowCount() == 0) {
103: _dsContact.reset();
104: _dsContact.insertRow();
105: } else
106: _dsContact.gotoFirst();
107: }
108:
109: //check the noedit parm. This allows the detail screen to be used as a zoom for a report
110: if (getParameter("noedit") == null) {
111: _cancel.setVisible(true);
112: _delete.setVisible(true);
113: _save.setVisible(true);
114: _displaybox1.setEnabled(true);
115: } else {
116: _cancel.setVisible(false);
117: _delete.setVisible(false);
118: _save.setVisible(false);
119: _displaybox1.setEnabled(false);
120: }
121: }
122: }
123:
124: /**
125: * This event is used to fill out the PageListener interface, but isn't used in this controller.
126: */
127: public void pageRequestEnd(PageEvent p) {
128: }
129:
130: /**
131: * This event is used to fill out the PageListener intrface, but isn't used in this controller.
132: */
133:
134: public void pageSubmitEnd(PageEvent p) {
135: }
136:
137: /**
138: * This event is used to fill out the PageListener intrface, but isn't used in this controller.
139: */
140: public void pageSubmitted(PageEvent p) {
141: }
142:
143: }
|