KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > jtrac > webflow > ConfigFormAction


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.webflow;
18
19 import info.jtrac.domain.Config;
20 import info.jtrac.util.ValidationUtils;
21 import org.springframework.beans.propertyeditors.StringTrimmerEditor;
22 import org.springframework.validation.DataBinder;
23 import org.springframework.webflow.execution.Event;
24 import org.springframework.webflow.execution.RequestContext;
25 import org.springframework.webflow.execution.ScopeType;
26
27 /**
28  * Multiaction that participates in the config editing flow
29  */

30 public class ConfigFormAction extends AbstractFormAction {
31     
32     public ConfigFormAction() {
33         setFormObjectClass(Config.class);
34         setFormObjectName("config");
35         setFormObjectScope(ScopeType.REQUEST);
36     }
37     
38     @Override JavaDoc
39     protected void initBinder(RequestContext request, DataBinder binder) {
40         binder.registerCustomEditor(String JavaDoc.class, new StringTrimmerEditor(true));
41     }
42     
43     @Override JavaDoc
44     public Object JavaDoc createFormObject(RequestContext context) {
45         String JavaDoc param = ValidationUtils.getParameter(context, "param");
46         String JavaDoc value = jtrac.loadConfig(param);
47         if (value == null) {
48             return new Config(param, null);
49         }
50         return new Config(param, value);
51     }
52     
53     public Event configFormHandler(RequestContext context) throws Exception JavaDoc {
54         Config config = (Config) getFormObject(context);
55         jtrac.storeConfig(config);
56         return success();
57     }
58     
59 }
60
Popular Tags