本文整理汇总了Java中org.apache.commons.validator.Form类的典型用法代码示例。如果您正苦于以下问题:Java Form类的具体用法?Java Form怎么用?Java Form使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Form类属于org.apache.commons.validator包,在下文中一共展示了Form类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: setupValidator
import org.apache.commons.validator.Form; //导入依赖的package包/类
/**
* バリデータをセットアップします。
*
*
* @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());
}
}
开发者ID:seasarorg,项目名称:sa-struts,代码行数:35,代码来源:ActionCustomizer.java
示例2: processAnnotation
import org.apache.commons.validator.Form; //导入依赖的package包/类
/**
* アノテーションを処理します。
*
*
* @param propertyName
* プロパティ名
* @param annotation
* アノテーション
* @param validatorResources
* 検証リソース
* @param forms
* メソッド名をキーにしたフォームのマップ
*/
protected void processAnnotation(String propertyName,
Annotation annotation, S2ValidatorResources validatorResources,
Map<String, Form> forms) {
Class<? extends Annotation> annotationType = annotation
.annotationType();
Annotation metaAnnotation = annotationType
.getAnnotation(Validator.class);
if (metaAnnotation == null) {
return;
}
String validatorName = getValidatorName(metaAnnotation);
Map<String, Object> props = AnnotationUtil.getProperties(annotation);
registerValidator(propertyName, validatorName, props,
validatorResources, forms);
}
开发者ID:seasarorg,项目名称:sa-struts,代码行数:29,代码来源:ActionCustomizer.java
示例3: get
import org.apache.commons.validator.Form; //导入依赖的package包/类
public Form get(Locale locale, Object formKey) {
return get(
locale.getLanguage(),
locale.getCountry(),
locale.getVariant(),
formKey);
}
开发者ID:GovernIB,项目名称:sistra,代码行数:8,代码来源:DynValidatorResources.java
示例4: getForm
import org.apache.commons.validator.Form; //导入依赖的package包/类
@Override
public Form getForm(Locale locale, String formKey) {
if (!initialized) {
initialize();
}
Form form = forms.get(formKey);
if (form == null) {
if (HotdeployUtil.isHotdeploy() && formKey.endsWith("Form")) {
SingletonS2ContainerFactory.getContainer().getComponentDef(
formKey.substring(0, formKey.length() - 4));
form = forms.get(formKey);
}
}
return form;
}
开发者ID:seasarorg,项目名称:sa-struts,代码行数:16,代码来源:S2ValidatorResources.java
示例5: testRegisterValidator
import org.apache.commons.validator.Form; //导入依赖的package包/类
/**
* @throws Exception
*/
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"));
}
开发者ID:seasarorg,项目名称:sa-struts,代码行数:18,代码来源:ActionCustomizerTest.java
示例6: testRegisterValidator_target
import org.apache.commons.validator.Form; //导入依赖的package包/类
/**
* @throws Exception
*/
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"));
}
开发者ID:seasarorg,项目名称:sa-struts,代码行数:18,代码来源:ActionCustomizerTest.java
示例7: testProcessAnnotation
import org.apache.commons.validator.Form; //导入依赖的package包/类
/**
* @throws Exception
*/
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"));
}
开发者ID:seasarorg,项目名称:sa-struts,代码行数:13,代码来源:ActionCustomizerTest.java
示例8: testSetupValidator
import org.apache.commons.validator.Form; //导入依赖的package包/类
/**
* @throws Exception
*/
public void testSetupValidator() throws Exception {
S2ActionMapping actionMapping = customizer
.createActionMapping(getComponentDef("aaa_bbbAction"));
customizer.setupValidator(actionMapping, validatorResources);
Form form = validatorResources.getForm(Locale.getDefault(),
"aaa_bbbActionForm_execute2");
assertNotNull(form);
org.apache.commons.validator.Field f = form.getField("hoge");
assertEquals("hoge", f.getProperty());
assertEquals("required", f.getDepends());
}
开发者ID:seasarorg,项目名称:sa-struts,代码行数:15,代码来源:ActionCustomizerTest.java
示例9: renderJavascript
import org.apache.commons.validator.Form; //导入依赖的package包/类
/**
* Returns fully rendered JavaScript.
* @since Struts 1.2
*/
protected String renderJavascript() throws JspException {
StringBuffer results = new StringBuffer();
ModuleConfig config = TagUtils.getInstance().getModuleConfig(pageContext);
ValidatorResources resources =
(ValidatorResources) pageContext.getAttribute(
ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix(),
PageContext.APPLICATION_SCOPE);
if (resources == null) {
throw new JspException(
"ValidatorResources not found in application scope under key \""
+ ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix() + "\"");
}
Locale locale = TagUtils.getInstance().getUserLocale(this.pageContext, null);
Form form = resources.getForm(locale, formName);
if ("true".equalsIgnoreCase(dynamicJavascript) && form == null)
{
throw new JspException("No form found under '"
+ formName
+ "' in locale '"
+ locale
+ "'");
}
if (form != null) {
if ("true".equalsIgnoreCase(dynamicJavascript)) {
results.append(
this.createDynamicJavascript(config, resources, locale, form));
} else if ("true".equalsIgnoreCase(staticJavascript)) {
results.append(this.renderStartElement());
if ("true".equalsIgnoreCase(htmlComment)) {
results.append(HTML_BEGIN_COMMENT);
}
}
}
if ("true".equalsIgnoreCase(staticJavascript)) {
results.append(getJavascriptStaticMethods(resources));
}
if (form != null
&& ("true".equalsIgnoreCase(dynamicJavascript)
|| "true".equalsIgnoreCase(staticJavascript))) {
results.append(getJavascriptEnd());
}
return results.toString();
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:59,代码来源:JavascriptValidatorTag.java
示例10: createActionList
import org.apache.commons.validator.Form; //导入依赖的package包/类
/**
* Get List of actions for the given Form.
* @param resources
* @param form
* @return A sorted List of ValidatorAction objects.
*/
private List createActionList(ValidatorResources resources, Form form) {
List actionMethods = new ArrayList();
Iterator iterator = form.getFields().iterator();
while (iterator.hasNext()) {
Field field = (Field) iterator.next();
for (Iterator x = field.getDependencyList().iterator(); x.hasNext();) {
Object o = x.next();
if (o != null && !actionMethods.contains(o)) {
actionMethods.add(o);
}
}
}
List actions = new ArrayList();
// Create list of ValidatorActions based on actionMethods
iterator = actionMethods.iterator();
while (iterator.hasNext()) {
String depends = (String) iterator.next();
ValidatorAction va = resources.getValidatorAction(depends);
// throw nicer NPE for easier debugging
if (va == null) {
throw new NullPointerException(
"Depends string \""
+ depends
+ "\" was not found in validator-rules.xml.");
}
if (va.getJavascript() != null && va.getJavascript().length() > 0) {
actions.add(va);
} else {
iterator.remove();
}
}
Collections.sort(actions, actionComparator);
return actions;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:51,代码来源:JavascriptValidatorTag.java
示例11: validate
import org.apache.commons.validator.Form; //导入依赖的package包/类
/**
* Validates the value of the specified Field on the target Object
*
* @param object
* @param fieldName
* @return a Set of Validation Error Keys
* @throws ValidationException
*/
public Set<String> validate(Object object, String fieldName)
throws ValidationException
{
try
{
Set<String> errorKeys = new HashSet<String>();
String objectId = object.getClass().getName();
//Setup the Validator
Validator validator = new Validator(this.validatorResources, objectId);
validator.setParameter(Validator.BEAN_PARAM, object);
validator.setFieldName(fieldName);
ValidatorResults results = validator.validate();
Form form = this.validatorResources.getForm(Locale.getDefault(), objectId);
Iterator propertyNames = results.getPropertyNames().iterator();
while(propertyNames.hasNext())
{
String property = (String)propertyNames.next();
ValidatorResult result = results.getValidatorResult(property);
Map actionMap = result.getActionMap();
Iterator keys = actionMap.keySet().iterator();
while (keys.hasNext())
{
String actionName = (String) keys.next();
if (!result.isValid(actionName))
{
Field field = form.getField(property);
Arg[] args = field.getArgs(actionName);
if(args != null)
{
for(int i=0; i<args.length; i++)
{
errorKeys.add(args[i].getKey());
}
}
}
}
}
return errorKeys;
}
catch(Exception e)
{
log.error(this, e);
throw new ValidationException(e);
}
}
开发者ID:ZalemSoftware,项目名称:OpenMobster,代码行数:58,代码来源:ObjectValidator.java
示例12: renderJavascript
import org.apache.commons.validator.Form; //导入依赖的package包/类
/**
* Returns fully rendered JavaScript.
*
* @since Struts 1.2
*/
protected String renderJavascript()
throws JspException {
StringBuffer results = new StringBuffer();
ModuleConfig config =
TagUtils.getInstance().getModuleConfig(pageContext);
ValidatorResources resources =
(ValidatorResources) pageContext.getAttribute(
ValidatorPlugIn.VALIDATOR_KEY
+ config.getPrefix(), PageContext.APPLICATION_SCOPE);
if (resources == null) {
throw new JspException(
"ValidatorResources not found in application scope under key \""
+ ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix() + "\"");
}
Locale locale =
TagUtils.getInstance().getUserLocale(this.pageContext, null);
Form form = null;
if ("true".equalsIgnoreCase(dynamicJavascript)) {
form = resources.getForm(locale, formName);
if (form == null) {
throw new JspException("No form found under '" + formName
+ "' in locale '" + locale
+ "'. A form must be defined in the "
+ "Commons Validator configuration when "
+ "dynamicJavascript=\"true\" is set.");
}
}
if (form != null) {
if ("true".equalsIgnoreCase(dynamicJavascript)) {
results.append(this.createDynamicJavascript(config, resources,
locale, form));
} else if ("true".equalsIgnoreCase(staticJavascript)) {
results.append(this.renderStartElement());
if ("true".equalsIgnoreCase(htmlComment)) {
results.append(HTML_BEGIN_COMMENT);
}
}
}
if ("true".equalsIgnoreCase(staticJavascript)) {
results.append(getJavascriptStaticMethods(resources));
}
if ((form != null)
&& ("true".equalsIgnoreCase(dynamicJavascript)
|| "true".equalsIgnoreCase(staticJavascript))) {
results.append(getJavascriptEnd());
}
return results.toString();
}
开发者ID:SonarSource,项目名称:sonar-scanner-maven,代码行数:63,代码来源:JavascriptValidatorTag.java
示例13: createActionList
import org.apache.commons.validator.Form; //导入依赖的package包/类
/**
* Get List of actions for the given Form.
*
* @param resources
* @param form
* @return A sorted List of ValidatorAction objects.
*/
private List createActionList(ValidatorResources resources, Form form) {
List actionMethods = new ArrayList();
Iterator iterator = form.getFields().iterator();
while (iterator.hasNext()) {
Field field = (Field) iterator.next();
for (Iterator x = field.getDependencyList().iterator();
x.hasNext();) {
Object o = x.next();
if ((o != null) && !actionMethods.contains(o)) {
actionMethods.add(o);
}
}
}
List actions = new ArrayList();
// Create list of ValidatorActions based on actionMethods
iterator = actionMethods.iterator();
while (iterator.hasNext()) {
String depends = (String) iterator.next();
ValidatorAction va = resources.getValidatorAction(depends);
// throw nicer NPE for easier debugging
if (va == null) {
throw new NullPointerException("Depends string \"" + depends
+ "\" was not found in validator-rules.xml.");
}
if ((va.getJavascript() != null)
&& (va.getJavascript().length() > 0)) {
actions.add(va);
} else {
iterator.remove();
}
}
Collections.sort(actions, actionComparator);
return actions;
}
开发者ID:SonarSource,项目名称:sonar-scanner-maven,代码行数:53,代码来源:JavascriptValidatorTag.java
示例14: printResults
import org.apache.commons.validator.Form; //导入依赖的package包/类
/**
* Dumps out the Bean in question and the results of validating it.
*/
public static void printResults(
ValidateBean bean,
ValidatorResults results,
ValidatorResources resources) {
boolean success = true;
// Start by getting the form for the current locale and Bean.
Form form = resources.getForm(Locale.getDefault(), "ValidateBean");
System.out.println("\n\nValidating:");
System.out.println(bean);
// Iterate over each of the properties of the Bean which had messages.
Iterator<String> propertyNames = results.getPropertyNames().iterator();
while (propertyNames.hasNext()) {
String propertyName = propertyNames.next();
// Get the Field associated with that property in the Form
Field field = form.getField(propertyName);
// Look up the formatted name of the field from the Field arg0
String prettyFieldName = apps.getString(field.getArg(0).getKey());
// Get the result of validating the property.
ValidatorResult result = results.getValidatorResult(propertyName);
// Get all the actions run against the property, and iterate over their names.
Iterator<String> keys = result.getActions();
while (keys.hasNext()) {
String actName = keys.next();
// Get the Action for that name.
ValidatorAction action = resources.getValidatorAction(actName);
// If the result is valid, print PASSED, otherwise print FAILED
System.out.println(
propertyName
+ "["
+ actName
+ "] ("
+ (result.isValid(actName) ? "PASSED" : "FAILED")
+ ")");
//If the result failed, format the Action's message against the formatted field name
if (!result.isValid(actName)) {
success = false;
String message = apps.getString(action.getMsg());
Object[] args = { prettyFieldName };
System.out.println(
" Error message will be: "
+ MessageFormat.format(message, args));
}
}
}
if (success) {
System.out.println("FORM VALIDATION PASSED");
} else {
System.out.println("FORM VALIDATION FAILED");
}
}
开发者ID:ManfredTremmel,项目名称:gwt-commons-validator,代码行数:67,代码来源:ValidateExample.java
示例15: registerValidator
import org.apache.commons.validator.Form; //导入依赖的package包/类
/**
* バリデータを登録します。
*
*
* @param propertyName
* プロパティ名
* @param validatorName
* バリデータ名
* @param props
* バリデータのプロパティ
* @param validatorResources
* 検証リソース
* @param forms
* メソッド名をキーにしたフォームのマップ
*/
protected void registerValidator(String propertyName, String validatorName,
Map<String, Object> props, S2ValidatorResources validatorResources,
Map<String, Form> forms) {
org.apache.commons.validator.Field field = createField(propertyName,
validatorName, props, validatorResources);
for (Iterator<String> i = forms.keySet().iterator(); i.hasNext();) {
String methodName = i.next();
if (!isTarget(methodName, (String) props.get("target"))) {
continue;
}
Form form = forms.get(methodName);
form.addField(field);
}
}
开发者ID:seasarorg,项目名称:sa-struts,代码行数:30,代码来源:ActionCustomizer.java
示例16: addForm
import org.apache.commons.validator.Form; //导入依赖的package包/类
/**
* フォームを追加します。
*
* @param form
* フォーム
*/
public void addForm(Form form) {
forms.put(form.getName(), form);
}
开发者ID:seasarorg,项目名称:sa-struts,代码行数:10,代码来源:S2ValidatorResources.java
注:本文中的org.apache.commons.validator.Form类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论