KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > ejosa > piggybank > presentation > enhydra > SavePage


1 /**
2  * Title: OpenUSS - Open Source University Support System
3  * My Piggy Bank Example
4  * Description: Enhydra Presentation Object
5  * Copyright: Copyright (c) 2003 by B. Lofi Dewanto, T. Menzel
6  * Company: University of Muenster, HTWK Leipzig
7  * @author B. Lofi Dewanto, T. Menzel
8  * @version 1.1
9  */

10 package net.sourceforge.ejosa.piggybank.presentation.enhydra;
11
12 import com.lutris.appserver.server.httpPresentation.*;
13
14 //import com.lutris.xml.xmlc.*;
15

16 import java.io.*;
17
18 import java.text.*;
19
20 import java.util.*;
21
22 import net.sourceforge.ejosa.piggybank.spec.*;
23 import net.sourceforge.ejosa.piggybank.spec.business.*;
24 import net.sourceforge.ejosa.piggybank.spec.system.*;
25
26 import org.openuss.presentation.enhydra.framework.*;
27
28 import org.openuss.utility.*;
29
30 import org.w3c.dom.*;
31 import org.w3c.dom.html.*;
32
33
34 /**
35  * Save Page
36  *
37  * @author B. Lofi Dewanto, T. Menzel
38  * @version 1.1
39  */

40 public class SavePage extends FoundationPO {
41     // Form parameter
42
protected String JavaDoc amount = null;
43
44     // Page
45
private SaveHTML mPage;
46
47     /**
48      * Default event. Just show the page.
49      */

50     public String JavaDoc handleDefault() throws HttpPresentationException {
51         // Create the page
52
mPage = (SaveHTML) this.getComms().xmlcFactory.create(SaveHTML.class);
53
54         // Look for an error
55
String JavaDoc errorMsg = this.getSessionData().getAndClearUserMessage();
56
57         if (errorMsg == null) {
58             // No error
59
mPage.getElementTStatusbar().getParentNode()
60                  .removeChild(mPage.getElementTStatusbar());
61         } else {
62             // Error, put it in the statusbar
63
mPage.setTextTStatusbar(errorMsg);
64         }
65
66         // Work with the page
67
return showLayout(mPage);
68     }
69
70     /**
71      * Superclass method override.
72      */

73     public boolean loggedInUserRequired() {
74         // This page doesn't need a login
75
return false;
76     }
77
78     /**
79      * Show the page, override the method.
80      */

81     public String JavaDoc showLayout(Object JavaDoc page) throws BasePOException {
82         // Format the statusbar and treebar
83
super.showLayout(mPage);
84
85
86         // Save
87
showSave();
88
89         // Return the result
90
return mPage.toDocument();
91     }
92
93     /**
94      * Save.
95      */

96     private void showSave() throws FoundationPOException {
97         // Get the form data
98
// -----------------
99
try {
100             amount = "0";
101
102             if (this.getComms().request.getParameter("amount") != null) {
103                 try {
104                     int temp = Integer.parseInt(
105                                        this.getComms().request.getParameter(
106                                                "amount"));
107                     amount = "" + temp;
108                 } catch (NumberFormatException JavaDoc nfe) {
109                     //System.out.println("Error: NumberFormatException: " + nfe);
110
}
111             }
112         } catch (Exception JavaDoc ex) {
113             System.out.println("Form Reader Error: " + ex);
114         }
115
116         // Business access
117
// !!!Only access to the specification!!!
118
try {
119             // Get the workflow object
120
CoinManager coinManager = CoinManagerFactory.createCoinManager(
121                                               "net.sourceforge.ejosa.piggybank.business.session.CoinManagerImpl");
122
123             //System.out.println("Coin: create a coin manager!");
124
// Create a value object / state object / data transfer object
125
Coin coin = CoinFactory.createCoin(
126                                 "net.sourceforge.ejosa.piggybank.business.entity.CoinImpl");
127
128             String JavaDoc now = DateFormat.getDateInstance(DateFormat.SHORT,
129                                                     Locale.ENGLISH)
130                                    .format(new Date());
131
132             coin.setDate(now);
133             coin.setAmount(amount);
134             coin.setCurrency("Dollar");
135
136             coinManager.createCoin(coin);
137
138             //System.out.println("Coin: create it!");
139
} catch (Exception JavaDoc ex) {
140             System.out.println("EJB Error: " + ex);
141             ex.printStackTrace();
142         }
143
144
145         // Show...
146
mPage.setTextVAmount(amount);
147     }
148 }
Popular Tags