01: package simpleorm.simplewebapp.dbute;
02:
03: import simpleorm.core.SRecordInstance;
04: import simpleorm.core.SFieldMeta;
05: import simpleorm.simplewebapp.core.WException;
06: import simpleorm.simplewebapp.ute.WDummyMap;
07: import simpleorm.properties.SProperty;
08:
09: import java.util.Map;
10:
11: /**
12: * Extends SRecordInstance with map etc.
13: * Should be moved to SRecordInstance eventually.
14: */
15: public abstract class WRecordInstance extends SRecordInstance {
16:
17: static final SProperty SELECT_OPTIONS = new SProperty(
18: "SelectOptions");
19:
20: /** Set list of values for HTML SELECT/OPTION.
21: * Should be made more dynamic later, a method rather than a static list.
22: * (Can be acheived using SProperty interface, just subtype it.)
23: */
24: static public SFieldMeta setOptions(SFieldMeta field,
25: String... options) {
26: field.putProperty(SELECT_OPTIONS, options);
27: return field;
28: }
29:
30: /** Hack for jstl properties as
31: * ${foo[bar]} can only reference a Map, not a simple method with a parameter.
32: *
33: * (Used by list forms.
34: * <c:forEach items="${wPage.listRows}" var="row".../>...
35: * <c:out value="${row[value.dataName]}"/>
36: * row is a WRecordInstance, value gets the value out of the record.
37: * )
38: *
39: * A major problem with this approach is that there is no mechanism to filter
40: * or format the values per UI. Things should go through
41: */
42: public Map fieldValues() {
43: return new FieldValues();
44: // Map m = new HashMap();
45: // m.put("userId", getString(WUser.USER_ID));
46: // m.put("name", getString(WUser.NAME));
47: // m.put("phone", getString(WUser.PHONE));
48: // return m;
49: }
50:
51: /**
52: * A simple, readonly map of fieldname to field Value which is displayed.
53: * Only supports get, later should support keySet etc.
54: */
55: class FieldValues extends WDummyMap {
56: public Object get(Object key) {
57: SFieldMeta field = getMeta().getField((String) key);
58: if (field == null)
59: throw new WException("Field not found "
60: + WRecordInstance.this + "[" + key + "]");
61: Object value = getObject(field); //TODO not quite right, should be the displayed value...
62: return value;
63: }
64: }
65: }
|