1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.controller.config;
17
18 import java.util.Iterator;
19 import java.util.Map;
20
21 import org.apache.commons.validator.Form;
22 import org.apache.commons.validator.FormSet;
23 import org.seasar.tuigwaa.model.core.TgwAttribute;
24 import org.seasar.tuigwaa.util.TgwNameUtils;
25
26 import com.isenshi.util.converter.ConverterResource;
27
28 public class TableConfigGenerator extends ConfigGenerator {
29
30 private static final String PROTO_FORM = "customTableFormProto";
31
32 private static final String PROTO_ACTION = "actionCTableSave";
33
34 private CustomFormConfigGenerator generator;
35
36 public TableConfigGenerator(CustomFormConfigGenerator cformGenerator,
37 ConverterResource resource, ModuleConfigMetadata metadata,
38 Map formSetChache) {
39 super(metadata, resource, formSetChache);
40 this.generator = cformGenerator;
41 }
42
43 public void generate() {
44 String formName = generator.getFormName();
45 String actionName = generator.getActionName();
46 formName = TgwNameUtils.toCustomTableFormName(formName);
47 actionName = TgwNameUtils.toCustomTableSaveActionName(actionName);
48 super.generate(PROTO_FORM, formName, PROTO_ACTION, actionName);
49
50 FormSet formSet = createFormSet();
51 setValidator(formSet);
52 }
53
54 private FormSet createFormSet() {
55 FormSet fs = getFormSet(generator.getEntity().getDomainName(),
56 getFormName());
57 Form form = new Form();
58 form.setName(getFormName());
59 Iterator itr = generator.getEntity().getFieldIterator();
60 while (itr.hasNext()) {
61 TgwAttribute attr = (TgwAttribute) itr.next();
62 String attrName = attr.getName();
63 if (generator.hasField(attrName)) {
64 ValidatorUtils.bindField(form, attr, "rowSet");
65 }
66 }
67 fs.addForm(form);
68 return fs;
69 }
70 }