001: /**
002: * Title: OpenUSS - Open Source University Support System
003: * My Piggy Bank Example
004: * Description: Enhydra Presentation Object
005: * Copyright: Copyright (c) 2003 by B. Lofi Dewanto, T. Menzel
006: * Company: University of Muenster, HTWK Leipzig
007: * @author B. Lofi Dewanto, T. Menzel
008: * @version 1.1
009: */package net.sourceforge.ejosa.piggybank.presentation.enhydra;
010:
011: import com.lutris.appserver.server.httpPresentation.*;
012:
013: //import com.lutris.xml.xmlc.*;
014:
015: import java.io.*;
016:
017: import java.text.*;
018:
019: import java.util.*;
020:
021: import net.sourceforge.ejosa.piggybank.spec.*;
022: import net.sourceforge.ejosa.piggybank.spec.business.*;
023: import net.sourceforge.ejosa.piggybank.spec.system.*;
024:
025: import org.openuss.presentation.enhydra.framework.*;
026:
027: import org.openuss.utility.*;
028:
029: import org.w3c.dom.*;
030: import org.w3c.dom.html.*;
031:
032: /**
033: * Save Page
034: *
035: * @author B. Lofi Dewanto, T. Menzel
036: * @version 1.1
037: */
038: public class SavePage extends FoundationPO {
039: // Form parameter
040: protected String amount = null;
041:
042: // Page
043: private SaveHTML mPage;
044:
045: /**
046: * Default event. Just show the page.
047: */
048: public String handleDefault() throws HttpPresentationException {
049: // Create the page
050: mPage = (SaveHTML) this .getComms().xmlcFactory
051: .create(SaveHTML.class);
052:
053: // Look for an error
054: String errorMsg = this .getSessionData()
055: .getAndClearUserMessage();
056:
057: if (errorMsg == null) {
058: // No error
059: mPage.getElementTStatusbar().getParentNode().removeChild(
060: mPage.getElementTStatusbar());
061: } else {
062: // Error, put it in the statusbar
063: mPage.setTextTStatusbar(errorMsg);
064: }
065:
066: // Work with the page
067: return showLayout(mPage);
068: }
069:
070: /**
071: * Superclass method override.
072: */
073: public boolean loggedInUserRequired() {
074: // This page doesn't need a login
075: return false;
076: }
077:
078: /**
079: * Show the page, override the method.
080: */
081: public String showLayout(Object page) throws BasePOException {
082: // Format the statusbar and treebar
083: super .showLayout(mPage);
084:
085: // Save
086: showSave();
087:
088: // Return the result
089: return mPage.toDocument();
090: }
091:
092: /**
093: * Save.
094: */
095: private void showSave() throws FoundationPOException {
096: // Get the form data
097: // -----------------
098: try {
099: amount = "0";
100:
101: if (this .getComms().request.getParameter("amount") != null) {
102: try {
103: int temp = Integer.parseInt(this .getComms().request
104: .getParameter("amount"));
105: amount = "" + temp;
106: } catch (NumberFormatException nfe) {
107: //System.out.println("Error: NumberFormatException: " + nfe);
108: }
109: }
110: } catch (Exception ex) {
111: System.out.println("Form Reader Error: " + ex);
112: }
113:
114: // Business access
115: // !!!Only access to the specification!!!
116: try {
117: // Get the workflow object
118: CoinManager coinManager = CoinManagerFactory
119: .createCoinManager("net.sourceforge.ejosa.piggybank.business.session.CoinManagerImpl");
120:
121: //System.out.println("Coin: create a coin manager!");
122: // Create a value object / state object / data transfer object
123: Coin coin = CoinFactory
124: .createCoin("net.sourceforge.ejosa.piggybank.business.entity.CoinImpl");
125:
126: String now = DateFormat.getDateInstance(DateFormat.SHORT,
127: Locale.ENGLISH).format(new Date());
128:
129: coin.setDate(now);
130: coin.setAmount(amount);
131: coin.setCurrency("Dollar");
132:
133: coinManager.createCoin(coin);
134:
135: //System.out.println("Coin: create it!");
136: } catch (Exception ex) {
137: System.out.println("EJB Error: " + ex);
138: ex.printStackTrace();
139: }
140:
141: // Show...
142: mPage.setTextVAmount(amount);
143: }
144: }
|