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.database.function.UpdateExeFunction;
24 import org.seasar.tuigwaa.model.core.TgwAttribute;
25 import org.seasar.tuigwaa.model.core.TgwEntity;
26 import org.seasar.tuigwaa.system.Constants;
27
28 import com.isenshi.util.converter.ConverterResource;
29
30 public class CustomFormConfigGenerator extends EntityConfigGenerator {
31
32 private UpdateExeFunction updateExe;
33
34 public CustomFormConfigGenerator(ConverterResource resource,
35 TgwEntity entity, ModuleConfigMetadata metadata,
36 UpdateExeFunction updateExe, Map formSetCache) {
37 super(resource, entity, metadata, formSetCache);
38 this.updateExe = updateExe;
39 }
40
41 public void generate() {
42 String formName = getModuleConfigMetadata().generateCusotmFormName(
43 getEntity(), updateExe);
44 String actionName = getModuleConfigMetadata().generateCustomActionName(
45 getEntity(), updateExe);
46 generate(PROTO_FORM, formName, PROTO_ACTION, actionName);
47 addProperties();
48
49 FormSet formSet = createFormSet();
50 setValidator(formSet);
51 }
52
53 public boolean hasField(String attrName){
54 return updateExe.getDtoFieldList().contains(attrName);
55 }
56
57 private void addProperties() {
58 Iterator itr = getEntity().getFieldIterator();
59 while (itr.hasNext()) {
60 TgwAttribute field = (TgwAttribute) itr.next();
61 String fieldName = field.getName();
62
63 if (hasField(fieldName)){
64 bindFormProperty(field);
65 }
66 }
67 addProperty(Constants.PARAM_PAGENAME, "java.lang.String");
68 }
69
70 private FormSet createFormSet() {
71 FormSet fs = getFormSet(getEntity().getDomainName(), getFormName());
72 Form form = new Form();
73 form.setName(getActionMapping().getName());
74 Iterator itr = getEntity().getFieldIterator();
75 while (itr.hasNext()) {
76 TgwAttribute attr = (TgwAttribute) itr.next();
77 String attrName = attr.getName();
78
79 if (hasField(attrName)){
80 ValidatorUtils.bindField(form, attr);
81 }
82 }
83 fs.addForm(form);
84 return fs;
85 }
86 }