本文整理汇总了Java中org.apache.commons.validator.Field类的典型用法代码示例。如果您正苦于以下问题:Java Field类的具体用法?Java Field怎么用?Java Field使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Field类属于org.apache.commons.validator包,在下文中一共展示了Field类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getActionMessage
import org.apache.commons.validator.Field; //导入依赖的package包/类
/**
* Gets the <code>ActionMessage</code> based on the
* <code>ValidatorAction</code> message and the <code>Field</code>'s
* arg objects.
* @param request the servlet request
* @param va Validator action
* @param field the validator Field
*/
public static ActionMessage getActionMessage(
HttpServletRequest request,
ValidatorAction va,
Field field) {
String args[] =
getArgs(
va.getName(),
getMessageResources(request),
RequestUtils.getUserLocale(request, null),
field);
String msg =
field.getMsg(va.getName()) != null
? field.getMsg(va.getName())
: va.getMsg();
return new ActionMessage(msg, args);
}
示例2: validateIsDirectory
import org.apache.commons.validator.Field; //导入依赖的package包/类
/**
* Validates that the field value is an existing directory on the server that the application is running on.
*
* @param bean The Struts bean
* @param va the ValidatorAction
* @param field The Field
* @param messages The ActionMessages
* @param validator The Validator
* @param request The HttpServletRequest
* @param servletContext The ServletContext
* @return True if the directory exists
*/
public static boolean validateIsDirectory(
Object bean,
ValidatorAction va,
Field field,
ActionMessages messages,
Validator validator,
HttpServletRequest request,
ServletContext servletContext) {
// Get the value the user entered:
String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
File dir = new File(value.trim());
// Validate that this is a directory on the server that already exists:
if (!dir.isDirectory()) {
ActionMessage message = Resources.getActionMessage(validator, request, va, field);
messages.add(field.getKey(), message);
return false;
}
else
return true;
}
示例3: validateNamespaceIdentifier
import org.apache.commons.validator.Field; //导入依赖的package包/类
/**
* Validates that the String is a valid namespace identifier for OAI.
*
* @param bean The Struts bean
* @param va the ValidatorAction
* @param field The Field
* @param messages The ActionMessages
* @param validator The Validator
* @param request The HttpServletRequest
* @param servletContext The ServletContext
* @return True if valid
*/
public static boolean validateNamespaceIdentifier(
Object bean,
ValidatorAction va,
Field field,
ActionMessages messages,
Validator validator,
HttpServletRequest request,
ServletContext servletContext) {
// Get the value the user entered:
String repositoryIdentifier = ValidatorUtils.getValueAsString(bean, field.getProperty());
boolean isValid = (
repositoryIdentifier == null ||
repositoryIdentifier.length() == 0 ||
repositoryIdentifier.matches("[a-zA-Z][a-zA-Z0-9\\-]*(\\.[a-zA-Z][a-zA-Z0-9\\-]+)+"));
if(!isValid) {
ActionMessage message = Resources.getActionMessage(validator, request, va, field);
messages.add(field.getKey(), message);
}
return isValid;
}
示例4: getActionError
import org.apache.commons.validator.Field; //导入依赖的package包/类
/**
* Gets the <code>ActionError</code> based on the
* <code>ValidatorAction</code> message and the <code>Field</code>'s
* arg objects.
* @param request the servlet request
* @param va Validator action
* @param field the validator Field
* @deprecated Use getActionMessage() instead. This will be removed after
* Struts 1.2.
*/
public static ActionError getActionError(
HttpServletRequest request,
ValidatorAction va,
Field field) {
String args[] =
getArgs(
va.getName(),
getMessageResources(request),
RequestUtils.getUserLocale(request, null),
field);
String msg =
field.getMsg(va.getName()) != null
? field.getMsg(va.getName())
: va.getMsg();
return new ActionError(msg, args);
}
示例5: validateRequired
import org.apache.commons.validator.Field; //导入依赖的package包/类
/**
* Checks if the field isn't null and length of the field is greater than zero not
* including whitespace.
*
* @param bean The bean validation is being performed on.
* @param va The <code>ValidatorAction</code> that is currently being performed.
* @param field The <code>Field</code> object associated with the current
* field being validated.
* @param errors The <code>ActionMessages</code> object to add errors to if
* any validation errors occur.
* @param validator The <code>Validator</code> instance, used to access
* other field values.
* @param request Current request object.
* @return true if meets stated requirements, false otherwise.
*/
public static boolean validateRequired(Object bean,
ValidatorAction va, Field field,
ActionMessages errors,
Validator validator,
HttpServletRequest request) {
String value = null;
if (isString(bean)) {
value = (String) bean;
} else {
value = ValidatorUtils.getValueAsString(bean, field.getProperty());
}
if (GenericValidator.isBlankOrNull(value)) {
errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
return false;
} else {
return true;
}
}
示例6: validateShort
import org.apache.commons.validator.Field; //导入依赖的package包/类
/**
* Checks if the field can safely be converted to a short primitive.
*
* @param bean The bean validation is being performed on.
* @param va The <code>ValidatorAction</code> that is currently being performed.
* @param field The <code>Field</code> object associated with the current
* field being validated.
* @param errors The <code>ActionMessages</code> object to add errors to if
* any validation errors occur.
* @param validator The <code>Validator</code> instance, used to access
* other field values.
* @param request Current request object.
* @return true if valid, false otherwise.
*/
public static Object validateShort(Object bean,
ValidatorAction va, Field field,
ActionMessages errors,
Validator validator,
HttpServletRequest request) {
Object result = null;
String value = null;
if (isString(bean)) {
value = (String) bean;
} else {
value = ValidatorUtils.getValueAsString(bean, field.getProperty());
}
if (GenericValidator.isBlankOrNull(value)) {
return Boolean.TRUE;
}
result = GenericTypeValidator.formatShort(value);
if (result == null) {
errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
}
return result == null ? Boolean.FALSE : result;
}
示例7: validateInteger
import org.apache.commons.validator.Field; //导入依赖的package包/类
/**
* Checks if the field can safely be converted to an int primitive.
*
* @param bean The bean validation is being performed on.
* @param va The <code>ValidatorAction</code> that is currently being performed.
* @param field The <code>Field</code> object associated with the current
* field being validated.
* @param errors The <code>ActionMessages</code> object to add errors to if any
* validation errors occur.
* @param validator The <code>Validator</code> instance, used to access
* other field values.
* @param request Current request object.
* @return true if valid, false otherwise.
*/
public static Object validateInteger(Object bean,
ValidatorAction va, Field field,
ActionMessages errors,
Validator validator,
HttpServletRequest request) {
Object result = null;
String value = null;
if (isString(bean)) {
value = (String) bean;
} else {
value = ValidatorUtils.getValueAsString(bean, field.getProperty());
}
if (GenericValidator.isBlankOrNull(value)) {
return Boolean.TRUE;
}
result = GenericTypeValidator.formatInt(value);
if (result == null) {
errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
}
return result == null ? Boolean.FALSE : result;
}
示例8: validateLong
import org.apache.commons.validator.Field; //导入依赖的package包/类
/**
* Checks if the field can safely be converted to a long primitive.
*
* @param bean The bean validation is being performed on.
* @param va The <code>ValidatorAction</code> that is currently being performed.
* @param field The <code>Field</code> object associated with the current
* field being validated.
* @param errors The <code>ActionMessages</code> object to add errors to if any
* validation errors occur.
* @param validator The <code>Validator</code> instance, used to access
* other field values.
* @param request Current request object.
* @return true if valid, false otherwise.
*/
public static Object validateLong(Object bean,
ValidatorAction va, Field field,
ActionMessages errors,
Validator validator,
HttpServletRequest request) {
Object result = null;
String value = null;
if (isString(bean)) {
value = (String) bean;
} else {
value = ValidatorUtils.getValueAsString(bean, field.getProperty());
}
if (GenericValidator.isBlankOrNull(value)) {
return Boolean.TRUE;
}
result = GenericTypeValidator.formatLong(value);
if (result == null) {
errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
}
return result == null ? Boolean.FALSE : result;
}
示例9: validateFloat
import org.apache.commons.validator.Field; //导入依赖的package包/类
/**
* Checks if the field can safely be converted to a float primitive.
*
* @param bean The bean validation is being performed on.
* @param va The <code>ValidatorAction</code> that is currently being performed.
* @param field The <code>Field</code> object associated with the current
* field being validated.
* @param errors The <code>ActionMessages</code> object to add errors to if any
* validation errors occur.
* @param validator The <code>Validator</code> instance, used to access
* other field values.
* @param request Current request object.
* @return true if valid, false otherwise.
*/
public static Object validateFloat(Object bean,
ValidatorAction va, Field field,
ActionMessages errors,
Validator validator,
HttpServletRequest request) {
Object result = null;
String value = null;
if (isString(bean)) {
value = (String) bean;
} else {
value = ValidatorUtils.getValueAsString(bean, field.getProperty());
}
if (GenericValidator.isBlankOrNull(value)) {
return Boolean.TRUE;
}
result = GenericTypeValidator.formatFloat(value);
if (result == null) {
errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
}
return result == null ? Boolean.FALSE : result;
}
示例10: validateDouble
import org.apache.commons.validator.Field; //导入依赖的package包/类
/**
* Checks if the field can safely be converted to a double primitive.
*
* @param bean The bean validation is being performed on.
* @param va The <code>ValidatorAction</code> that is currently being performed.
* @param field The <code>Field</code> object associated with the current
* field being validated.
* @param errors The <code>ActionMessages</code> object to add errors to if any
* validation errors occur.
* @param validator The <code>Validator</code> instance, used to access
* other field values.
* @param request Current request object.
* @return true if valid, false otherwise.
*/
public static Object validateDouble(Object bean,
ValidatorAction va, Field field,
ActionMessages errors,
Validator validator,
HttpServletRequest request) {
Object result = null;
String value = null;
if (isString(bean)) {
value = (String) bean;
} else {
value = ValidatorUtils.getValueAsString(bean, field.getProperty());
}
if (GenericValidator.isBlankOrNull(value)) {
return Boolean.TRUE;
}
result = GenericTypeValidator.formatDouble(value);
if (result == null) {
errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
}
return result == null ? Boolean.FALSE : result;
}
示例11: validateEmail
import org.apache.commons.validator.Field; //导入依赖的package包/类
/**
* Checks if a field has a valid e-mail address.
*
* @param bean The bean validation is being performed on.
* @param va The <code>ValidatorAction</code> that is currently being performed.
* @param field The <code>Field</code> object associated with the current
* field being validated.
* @param errors The <code>ActionMessages</code> object to add errors to if any
* validation errors occur.
* @param validator The <code>Validator</code> instance, used to access
* other field values.
* @param request Current request object.
* @return True if valid, false otherwise.
*/
public static boolean validateEmail(Object bean,
ValidatorAction va, Field field,
ActionMessages errors,
Validator validator,
HttpServletRequest request) {
String value = null;
if (isString(bean)) {
value = (String) bean;
} else {
value = ValidatorUtils.getValueAsString(bean, field.getProperty());
}
if (!GenericValidator.isBlankOrNull(value) && !GenericValidator.isEmail(value)) {
errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
return false;
} else {
return true;
}
}
示例12: validateRequired
import org.apache.commons.validator.Field; //导入依赖的package包/类
/**
* Checks if the field is required.
*
* @return boolean If the field isn't <code>null</code> and
* has a length greater than zero, <code>true</code> is returned.
* Otherwise <code>false</code>.
*/
public static boolean validateRequired(Object bean, Field field) {
String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
String labelName = field.getProperty() + "Label";
try {
JLabel label = (JLabel)PropertyUtils.getProperty(bean, labelName);
String text = label.getText();
int ind = text.indexOf("*");
if (ind == -1){
label.setText(text + "*");
}
} catch (Exception e) {
}
return !GenericValidator.isBlankOrNull(value);
}
示例13: getVarValue
import org.apache.commons.validator.Field; //导入依赖的package包/类
/**
* Get the value of a variable.
*
* @param varName The variable name
* @param field the validator Field
* @param validator The Validator
* @param request the servlet request
* @param required Whether the variable is mandatory
* @return The variable's value
*/
public static String getVarValue(String varName, Field field,
Validator validator, HttpServletRequest request, boolean required) {
Var var = field.getVar(varName);
if (var == null) {
String msg = sysmsgs.getMessage("variable.missing", varName);
if (required) {
throw new IllegalArgumentException(msg);
}
if (log.isDebugEnabled()) {
log.debug(field.getProperty() + ": " + msg);
}
return null;
}
ServletContext application =
(ServletContext) validator.getParameterValue(SERVLET_CONTEXT_PARAM);
return getVarValue(var, application, request, required);
}
示例14: getArgs
import org.apache.commons.validator.Field; //导入依赖的package包/类
/**
* Gets the message arguments based on the current <code>ValidatorAction</code>
* and <code>Field</code>.
*
* @param actionName action name
* @param messages message resources
* @param locale the locale
* @param field the validator field
*/
public static String[] getArgs(String actionName,
MessageResources messages, Locale locale, Field field) {
String[] argMessages = new String[4];
Arg[] args =
new Arg[] {
field.getArg(actionName, 0), field.getArg(actionName, 1),
field.getArg(actionName, 2), field.getArg(actionName, 3)
};
for (int i = 0; i < args.length; i++) {
if (args[i] == null) {
continue;
}
if (args[i].isResource()) {
argMessages[i] = getMessage(messages, locale, args[i].getKey());
} else {
argMessages[i] = args[i].getKey();
}
}
return argMessages;
}
示例15: validateRequired
import org.apache.commons.validator.Field; //导入依赖的package包/类
/**
* Checks if the field isn't null and length of the field is greater than
* zero not including whitespace.
*
* @param bean The bean validation is being performed on.
* @param va The <code>ValidatorAction</code> that is currently
* being performed.
* @param field The <code>Field</code> object associated with the
* current field being validated.
* @param errors The <code>ActionMessages</code> object to add errors
* to if any validation errors occur.
* @param validator The <code>Validator</code> instance, used to access
* other field values.
* @param request Current request object.
* @return true if meets stated requirements, false otherwise.
*/
public static boolean validateRequired(Object bean, ValidatorAction va,
Field field, ActionMessages errors, Validator validator,
HttpServletRequest request) {
String value = null;
value = evaluateBean(bean, field);
if (GenericValidator.isBlankOrNull(value)) {
errors.add(field.getKey(),
Resources.getActionMessage(validator, request, va, field));
return false;
} else {
return true;
}
}