01: package simpleorm.simplewebapp.dbute;
02:
03: import simpleorm.simplewebapp.core.*;
04: import simpleorm.core.*;
05:
06: import java.util.ArrayList;
07:
08: /**
09: * Generic Data List Bean, can display data from any table.
10: * (Can display rows in any table.)
11: */
12: public class WGenericListPagelet extends WPageletList {
13: SResultSet res;
14:
15: public WGenericListPagelet(WPage wpage, String name) {
16: super (wpage, name);
17: }
18:
19: protected void queryData(SRecordMeta meta, SFieldMeta whereField,
20: Object whereValue, String sortName) throws Exception {
21: SQuery qry = meta.newQuery().like(whereField, whereValue);
22: if (sortName != null) {
23: SFieldMeta fld = meta.getField(sortName);
24: qry.rawOrderBy(fld, true);
25: }
26: res = qry.execute();
27: }
28:
29: protected @Override
30: boolean onListRow() throws Exception {
31: if (res == null || !res.hasNext())
32: return false;
33: SRecordInstance rec = res.getRecord();
34: for (WField wfield : getPage().getListFieldValues()) {
35: SFieldMeta sfield = rec.getMeta().getField(
36: wfield.getDataName());
37: Object value = rec.getObject(sfield);
38: //if ( logger().isDebug() ) logger().debug("onNotSubmitted "+ sfield + " == " + value);
39: wfield.setValue(value);
40:
41: ArrayList<WField> keys = new ArrayList();
42: if (sfield.getBoolean(SCon.SPRIMARY_KEY))
43: keys.add(wfield);
44: WFieldGroupList fields = (WFieldGroupList) getFieldGroup("list");
45: fields.setAnchorHRefFields(keys.toArray(new WField[keys
46: .size()]));
47: }
48: return true;
49: }
50: }
|