List of usage examples for org.apache.commons.validator Form Form
Form
From source file:jp.terasoluna.fw.validation.springmodules.CommonsValidatorExTest.java
/** * testValidate01() <br>/*from w w w . j av a2s . c o m*/ * <br> * * () <br> * A <br> * <br> * (????) super.validate():???<br> * * <br> * () ValidatorResults:super.validate()??<br> * () this.validatorException:null<br> * * <br> * super.validate()??????super.validate()??????? * <br> * * @throws Exception * ????? */ @Test public void testValidate01() throws Exception { // ?? CommonsValidatorEx_ValidatorResourcesStub01 resources = new CommonsValidatorEx_ValidatorResourcesStub01(); Form form = new Form(); resources.setForm(form); // super.validate()??????????? // Field????? // super.validate()????field.validate()? // ??? // super.validate()??field.validate()???????? CommonsValidatorEx_FieldStub01 field = new CommonsValidatorEx_FieldStub01(); List<Field> lFields = new ArrayList<Field>(); lFields.add(field); ReflectionTestUtils.setField(form, "lFields", lFields); ValidatorResults validatorResults = new ValidatorResults(); Map<String, ValidatorResult> hResults = new HashMap<String, ValidatorResult>(); ValidatorResult validatorResult = new ValidatorResult(field); hResults.put("test", validatorResult); ReflectionTestUtils.setField(validatorResults, "hResults", hResults); field.validateReturn = validatorResults; CommonsValidatorEx commonsValidatorEx = new CommonsValidatorEx(resources, "formName"); // ValidatorResults result = commonsValidatorEx.validate(); // // result??field.validate()???????? Map<?, ?> resultHResults = (Map<?, ?>) ReflectionTestUtils.getField(result, "hResults"); assertEquals(1, resultHResults.size()); assertSame(validatorResult, resultHResults.get("test")); }
From source file:jp.terasoluna.fw.validation.springmodules.CommonsValidatorExTest.java
/** * testValidate02() <br>//ww w . jav a2s .c o m * <br> * * () <br> * A,G <br> * <br> * (????) super.validate():ValidatorException?<br> * * <br> * () :super.validate()???ValidatorException<br> * () this.validatorException:super.validate()???ValidatorException<br> * * <br> * super.validate()?ValidatorException??????????????????? * <br> * * @throws Exception * ????? */ @Test public void testValidate02() throws Exception { // ?? CommonsValidatorEx_ValidatorResourcesStub01 resources = new CommonsValidatorEx_ValidatorResourcesStub01(); Form form = new Form(); resources.setForm(form); // super.validate()??????????? // Field????? // super.validate()????field.validate()? // ??? // super.validate()??field.validate()???validatorException // ???????? CommonsValidatorEx_FieldStub01 field = new CommonsValidatorEx_FieldStub01(); List<Field> lFields = new ArrayList<Field>(); lFields.add(field); ReflectionTestUtils.setField(form, "lFields", lFields); field.validatorException = new ValidatorException(); CommonsValidatorEx commonsValidatorEx = new CommonsValidatorEx(resources, "formName"); // try { commonsValidatorEx.validate(); fail(); } catch (ValidatorException e) { // // field.validate()???ValidatorException????? assertSame(field.validatorException, e); assertSame(e, commonsValidatorEx.getValidatorException()); } }
From source file:org.agnitas.service.impl.NewImportWizardServiceImpl.java
public void handleRow(String[] row) throws Exception { // If we haven't been sent the header data yet then we store them (but don't process them) if (columns == null) { columns = filedsFactory.createColumnHeader(row, importProfile); // final Form form = resources.getForm(Locale.getDefault(), FORM_NAME); final Form customForm = new Form(); customForm.setName(FORM_NAME);//w w w . j av a 2s. c om final FormSet formSet = new FormSet(); formSet.addForm(customForm); resources.addFormSet(formSet); filedsFactory.createRulesForCustomFields(columns, customForm, importRecipientsDao, importProfile); initColumnsNullableCheck(columns); } else { push("fields"); setDefaultMailType(); for (int idx = 0; (idx < columns.length) && (idx < row.length); idx++) { /* * if(!columns[idx].getImportedColumn()) { continue; } */ String value = row[idx]; if (StringUtils.isEmpty(value)) { value = getDefaultValueFromImportProfile(idx); } if (columns[idx].getColName().toLowerCase().equals(ImportUtils.MAIL_TYPE_DB_COLUMN)) { value = adjustMailtype(value); if (value != null) { push("mailtypeDefined"); apply(ImportUtils.MAIL_TYPE_DEFINED); pop("mailtypeDefined"); } } push(columns[idx].getColName()); apply(value); pop(columns[idx].getColName()); } pop("fields"); } }
From source file:org.seasar.struts.customizer.ActionCustomizer.java
/** * ????//from ww w .jav a 2 s . c om * * * @param actionMapping * * @param validatorResources * */ protected void setupValidator(S2ActionMapping actionMapping, S2ValidatorResources validatorResources) { Map<String, Form> forms = new HashMap<String, Form>(); for (String methodName : actionMapping.getExecuteMethodNames()) { if (actionMapping.getExecuteConfig(methodName).isValidator()) { Form form = new Form(); form.setName(actionMapping.getName() + "_" + methodName); forms.put(methodName, form); } } for (Class<?> clazz = actionMapping.getActionFormBeanDesc().getBeanClass(); clazz != null && clazz != Object.class; clazz = clazz.getSuperclass()) { for (Field field : ClassUtil.getDeclaredFields(clazz)) { for (Annotation anno : field.getDeclaredAnnotations()) { processAnnotation(field.getName(), anno, validatorResources, forms); } } } for (Iterator<Form> i = forms.values().iterator(); i.hasNext();) { validatorResources.addForm(i.next()); } }
From source file:org.seasar.struts.customizer.ActionCustomizerTest.java
/** * @throws Exception// w w w . j a v a 2s . co m */ public void testRegisterValidator() throws Exception { Map<String, Form> forms = new HashMap<String, Form>(); Form form = new Form(); forms.put("execute", form); Form form2 = new Form(); forms.put("execute2", form2); Field field = BbbAction.class.getDeclaredField("hoge"); Required r = field.getAnnotation(Required.class); Map<String, Object> props = AnnotationUtil.getProperties(r); customizer.registerValidator("hoge", "required", props, validatorResources, forms); assertNotNull(form.getField("hoge")); assertNotNull(form2.getField("hoge")); }
From source file:org.seasar.struts.customizer.ActionCustomizerTest.java
/** * @throws Exception//from w ww . ja v a 2 s. c o m */ public void testRegisterValidator_target() throws Exception { Map<String, Form> forms = new HashMap<String, Form>(); Form form = new Form(); forms.put("execute", form); Form form2 = new Form(); forms.put("execute2", form2); Field field = BbbAction.class.getDeclaredField("hoge2"); Validwhen v = field.getAnnotation(Validwhen.class); Map<String, Object> props = AnnotationUtil.getProperties(v); customizer.registerValidator("hoge2", "validwhen", props, validatorResources, forms); assertNotNull(form.getField("hoge2")); assertNull(form2.getField("hoge2")); }
From source file:org.seasar.struts.customizer.ActionCustomizerTest.java
/** * @throws Exception//from w w w. jav a2s . c om */ public void testProcessAnnotation() throws Exception { Map<String, Form> forms = new HashMap<String, Form>(); Form form = new Form(); forms.put("execute", form); Field field = BbbAction.class.getDeclaredField("hoge"); Required r = field.getAnnotation(Required.class); customizer.processAnnotation("hoge", r, validatorResources, forms); assertNotNull(form.getField("hoge")); }
From source file:org.seasar.struts.lessconfig.factory.AbstractValidatorAnnotationHandler.java
public Form createForm(String formName, Class formClass) { Form form = new Form(); form.setName(formName);// w ww . ja v a2 s . c o m BeanDesc beanDesc = BeanDescFactory.getBeanDesc(formClass); registerFields(form, new Field(), beanDesc); return form; }