/** * Merges the given <code>FormSet</code> into this one. If any of <code>depends</code> * s <code>Forms</code> are not in this <code>FormSet</code> then, include * them, else merge both <code>Forms</code>. Theoretically we should only * merge a "parent" formSet. * * @param depends FormSet to be merged * @since Validator 1.2.0 */ protected void merge(FormSet depends) { if (depends != null) { Map<String, Form> pForms = getForms(); Map<String, Form> dForms = depends.getForms(); for (Iterator<Entry<String, Form>> it = dForms.entrySet().iterator(); it.hasNext(); ) { Entry<String, Form> entry = it.next(); String key = entry.getKey(); Form pForm = pForms.get(key); if (pForm != null) {//merge, but principal 'rules', don't overwrite // anything pForm.merge(entry.getValue()); } else {//just add addForm(entry.getValue()); } } } merged = true; }
field.setDepends("capLetter"); form.addField(field); fs.addForm(form);
private ValidatorResources setupDateResources(String property, String action) { ValidatorResources resources = new ValidatorResources(); ValidatorAction va = new ValidatorAction(); va.setName(action); va.setClassname("org.apache.commons.validator.ValidatorTest"); va.setMethod("formatDate"); va.setMethodParams("java.lang.Object,org.apache.commons.validator.Field"); FormSet fs = new FormSet(); Form form = new Form(); form.setName("testForm"); Field field = new Field(); field.setProperty(property); field.setDepends(action); form.addField(field); fs.addForm(form); resources.addValidatorAction(va); resources.addFormSet(fs); resources.process(); return resources; }
/** * Merges the given <code>FormSet</code> into this one. If any of <code>depends</code> * s <code>Forms</code> are not in this <code>FormSet</code> then, include * them, else merge both <code>Forms</code>. Theoretically we should only * merge a "parent" formSet. * * @param depends FormSet to be merged * @since Validator 1.2.0 */ protected void merge(FormSet depends) { if (depends != null) { Map<String, Form> pForms = getForms(); Map<String, Form> dForms = depends.getForms(); for (Iterator<Entry<String, Form>> it = dForms.entrySet().iterator(); it.hasNext(); ) { Entry<String, Form> entry = it.next(); String key = entry.getKey(); Form pForm = pForms.get(key); if (pForm != null) {//merge, but principal 'rules', don't overwrite // anything pForm.merge(entry.getValue()); } else {//just add addForm(entry.getValue()); } } } merged = true; }
/** * Merges the given <code>FormSet</code> into this one. If any of <code>depends</code> * s <code>Forms</code> are not in this <code>FormSet</code> then, include * them, else merge both <code>Forms</code>. Theoretically we should only * merge a "parent" formSet. * * @param depends FormSet to be merged * @since Validator 1.2.0 */ protected void merge(FormSet depends) { if (depends != null) { Map pForms = getForms(); Map dForms = depends.getForms(); for (Iterator it = dForms.keySet().iterator(); it.hasNext(); ) { Object key = it.next(); Form pForm = (Form) pForms.get(key); if (pForm != null) {//merge, but principal 'rules', don't overwrite // anything pForm.merge((Form) dForms.get(key)); } else {//just add addForm((Form) dForms.get(key)); } } } merged = true; }
public Object invoke(MethodInvocation invocation) throws Throwable { String formKey; if (invocation.getArguments().length == 2) { formKey = (String) invocation.getArguments()[1]; } else { formKey = (String) invocation.getArguments()[3]; } if (formKey == null) { return invocation.proceed(); } ModuleConfig config = ModuleUtils.getInstance().getModuleConfig(S2StrutsContextUtil.getRequest()); Form form = this.validationCreator.createForm(config, formKey); if (form != null) { if (log.isDebugEnabled()) { log.debug("auto create " + form); } // initialize form... ValidatorResources resources = new ValidatorResources(); FormSet formSet = new FormSet(); formSet.addForm(form); resources.addFormSet(formSet); resources.process(); // ...initialized form return form; } return invocation.proceed(); }
private FormSet createValidatorFormSet(TgwEntity entity, ActionMapping mapping) { FormSet fs = getFormSet(entity.getDomainName(), entity.getName()); Form form = new Form(); form.setName(mapping.getName()); for (TgwAttribute attr : entity.getAttributes()) { ValidatorUtils.bindField(form, attr); } // overide fs.addForm(form); return fs; } }
private FormSet createFormSet() { FormSet fs = getFormSet(getEntity().getDomainName(), getFormName()); Form form = new Form(); form.setName(getActionMapping().getName()); for (TgwAttribute attr : getEntity().getAttributes()) { String attrName = attr.getName(); if (hasField(attrName)) { ValidatorUtils.bindField(form, attr); } } fs.addForm(form); return fs; } }
private FormSet createFormSet() { FormSet fs = getFormSet(generator.getEntity().getDomainName(), getFormName()); Form form = new Form(); form.setName(getFormName()); for (TgwAttribute attr : generator.getEntity().getAttributes()) { String attrName = attr.getName(); if (generator.hasField(attrName)) { ValidatorUtils.bindField(form, attr, "rowSet"); } } fs.addForm(form); return fs; } }
private void registerValidations(ModuleConfig config) { // Create Forms. ValidatorResources currentResources = getValidatorResources(config); FormSet formSet = new FormSet(); FormBeanConfig[] formConfigs = config.findFormBeanConfigs(); for (int i = 0; i < formConfigs.length; i++) { if (!registeredValidation(currentResources, formConfigs[i])) { Class clazz = ClassUtil.forName(formConfigs[i].getType()); String name = formConfigs[i].getName(); Form form = this.validationCreator.createForm(config, clazz, name); if (form != null) { formSet.addForm(form); if (log.isDebugEnabled()) { log.debug("auto register " + form); } } } } // Initialize ValidatorResources if (formSet.getForms().size() != 0) { ValidatorResources resources = new ValidatorResources(); resources.addFormSet(formSet); resources.process(); addValidatorResources(config, resources); } }