e.g. Calendar Search Help
You must enter a value before pressing Search
tomcat

Class: sessions.DummyCart   ©

 OK to copy?
01 /*
02 * Copyright 2004 The Apache Software Foundation
03 *
04 * Licensed under the Apache License, Version 2.0 (the "License");
05 * you may not use this file except in compliance with the License.
06 * You may obtain a copy of the License at
07 *
08 *     http://www.apache.org/licenses/LICENSE-2.0
09 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package sessions;
17 
18 import javax.servlet.http.*;
19 import java.util.Vector;
20 import java.util.Enumeration;
21 
22 public class DummyCart {
Rate23     Vector v = new Vector();
24     String submit = null;
25     String item = null;
26     
27     private void addItem(String name) {
28     v.addElement(name);
29     }
30 
31     private void removeItem(String name) {
32     v.removeElement(name);
33     }
34 
35     public void setItem(String name) {
36     item = name;
37     }
38     
39     public void setSubmit(String s) {
40     submit = s;
41     }
42 
43     public String[] getItems() {
44     String[] s = new String[v.size()];
45     v.copyInto(s);
46     return s;
47     }
48     
49     public void processRequest(HttpServletRequest request) {
50     // null value for submit - user hit enter instead of clicking on 
51     // "add" or "remove"
52     if (submit == null) 
53         addItem(item);
54 
55     if (submit.equals("add"))
56         addItem(item);
57     else if (submit.equals("remove")) 
58         removeItem(item);
59     
60     // reset at the end of the request
61     reset();
62     }
63 
64     // reset
65     private void reset() {
66     submit = null;
67     item = null;
68     }
69 }

            
All Examples in File:
Example
Line
Rating (found
useful by...)
23 0% of 0
23 0% of 0