API Overview API Index Package Overview Direct link to this page
JavaOnTracks 0.1.2
  net.jot.web.forms. JOTPropertiesForm View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

/*
------------------------------------
JavaOnTracks          Thibaut Colar
tcolar-jot AT colar DOT net
Artistic Licence 2.0
http://www.javaontracks.net
------------------------------------
 */
package net.jot.web.forms;

import java.util.Properties;

import net.jot.web.JOTFlowRequest;
import net.jot.web.forms.ui.JOTFormField;

/**
 * Generic class that provides easy mapping of a property file to a form
 * This allow for an easy "setup form" where as the setup options are stored in a property file.
 * Extend to map your own property file.
 * @author thibautc
 *
 */
public abstract class JOTPropertiesForm extends JOTGeneratedForm
{
	protected Properties props;
	
	public void addFormField(JOTFormField field)
	{
		String obj=props.getProperty(field.getName());
		if(obj!=null) field.setDefaultValue(obj);
		super.addFormField(field);
	}
	
        /**
Will be called when the form data changed (in the request / form submission)
To update the data values here.
@param request 
@throws java.lang.Exception 
*/
	public void refreshData(JOTFlowRequest request) throws Exception
	{
		updateProperties(request);
		super.refreshData(request);
	}
	
	/**
	 * Implement to set/load the properties.
         * This method should set the "props" variable (Properties object loaded from some property file)
         * 
	 * @param request
	 */
	public abstract void updateProperties(JOTFlowRequest request);
	/**
	 * Implement to save the properties back where they came from (your property file).
         * Note: save the "props" object to your property file.
	 * @throws Exception
	 */
	public abstract void saveProperties() throws Exception;
	
        /**
Call this to save the new form values to the property file 
This will save the values and then call your saveProperties implementation
@param request 
@throws java.lang.Exception 
*/
	public void save(JOTFlowRequest request) throws Exception
	{
		for(int i=0;i!=items.size();i++)
		{
			if(items.get(i) instanceof JOTFormField)
			{
				JOTFormField field=(JOTFormField)items.get(i);
				String name=field.getName();
				JOTFormElement el=get(name);
				if(el!=null && field.isSaveAutomatically())
				{
					Object value=el.getValue();
					props.setProperty(name, (String)value);
				}
			}
		}
		// then save the model
		saveProperties();
	}

}

Generated By: JavaOnTracks Doclet 0.1.5     ©Thibaut Colar