KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > examples > listexample > SimpleCountryForm


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 org.apache.myfaces.examples.listexample;
17
18 import javax.faces.context.FacesContext;
19
20
21 /**
22  * DOCUMENT ME!
23  * @author Manfred Geiler (latest modification by $Author: matzew $)
24  * @author Thomas Spiegl
25  * @version $Revision: 1.1 $ $Date: 2005/03/24 16:47:10 $
26  */

27 public class SimpleCountryForm
28 {
29     private long _id;
30     private String JavaDoc _name;
31     private String JavaDoc _isoCode;
32
33     public long getId()
34     {
35         return _id;
36     }
37
38     public void setId(long id)
39     {
40         _id = id;
41         if (_id > 0)
42         {
43             SimpleCountry simpleCountry = getList().getSimpleCountry(_id);
44             if (simpleCountry == null)
45             {
46                 return;
47             }
48             _name = simpleCountry.getName();
49             _isoCode = simpleCountry.getIsoCode();
50         }
51     }
52
53     public void setIsoCode(String JavaDoc isoCode)
54     {
55         _isoCode = isoCode;
56     }
57
58     public String JavaDoc getIsoCode()
59     {
60         return _isoCode;
61     }
62
63     public String JavaDoc getName()
64     {
65         return _name;
66     }
67
68     public void setName(String JavaDoc name)
69     {
70         _name = name;
71     }
72
73     private SimpleCountry getSimpleCountry()
74     {
75         return new SimpleCountry(_id, _name, _isoCode, null, null);
76     }
77
78     public String JavaDoc save()
79     {
80         getList().saveSimpleCountry(getSimpleCountry());
81         return "ok_next";
82     }
83
84     public String JavaDoc delete()
85     {
86         getList().deleteSimpleCountry(getSimpleCountry());
87         return "ok_next";
88     }
89
90     public String JavaDoc apply()
91     {
92         getList().saveSimpleCountry(getSimpleCountry());
93         return "ok";
94     }
95
96     private SimpleCountryList getList()
97     {
98         Object JavaDoc obj = FacesContext.getCurrentInstance().getApplication().getVariableResolver()
99             .resolveVariable(FacesContext.getCurrentInstance(), "countryList");
100         return (SimpleCountryList) obj;
101
102     }
103 }
104
Popular Tags