KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > jtrac > util > UserEditor


1 /*
2  * Copyright 2002-2005 the original author or authors.
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
17 package info.jtrac.util;
18
19 import info.jtrac.Jtrac;
20 import info.jtrac.domain.User;
21 import java.beans.PropertyEditorSupport JavaDoc;
22
23 /**
24  * Property Editor for binding / unbinding User objects into JSP forms
25  */

26 public class UserEditor extends PropertyEditorSupport JavaDoc {
27     
28     private Jtrac jtrac;
29     
30     public UserEditor(Jtrac jtrac) {
31         this.jtrac = jtrac;
32     }
33     
34     @Override JavaDoc
35     public void setAsText(String JavaDoc text) {
36         if (text == null || text.equals("")) {
37             setValue(null);
38         } else {
39             int id = Integer.parseInt(text);
40             setValue(jtrac.loadUser(id));
41         }
42     }
43
44     @Override JavaDoc
45     public String JavaDoc getAsText() {
46         Object JavaDoc o = getValue();
47         if (o == null) {
48             return "";
49         }
50         User user = (User) o;
51         return user.getId() + "";
52     }
53     
54 }
55
Popular Tags