Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
1.5.4
-
None
-
Windows 7, Netbeans 7.0.1, Java 6 SE (HotSpot)
Description
PROBLEM:
<e1nPL> hi I am having such problem:
<e1nPL> I have implemented validator by implementing IValidator<T> interface
<e1nPL> and I have impelemnted the same validator by extending AbstractValidator<T> class
CODE:
===================== VALIDATOR EXTENDED FROM AbstractValidator =====================
package com.mycompany;
import java.util.regex.Pattern;
import org.apache.wicket.IClusterable;
import org.apache.wicket.util.lang.Classes;
import org.apache.wicket.validation.IValidatable;
import org.apache.wicket.validation.IValidator;
import org.apache.wicket.validation.ValidationError;
import org.apache.wicket.validation.validator.AbstractValidator;
/**
*
- @author e1n
*/
public class PasswordPolicyValidator<T> extends AbstractValidator<T> {
private static final Pattern UPPER = Pattern.compile("[A-Z]");
private static final Pattern LOWER = Pattern.compile("[a-z]");
private static final Pattern NUMBER = Pattern.compile("[0-9]");
@Override
public void onValidate(IValidatable<T> validatable) {
final String password = (String)validatable.getValue();
if (!NUMBER.matcher(password).find())
{ error(validatable, "no-digit"); }if (!LOWER.matcher(password).find()) { error(validatable, "no-lower"); }
if (!UPPER.matcher(password).find()) { error(validatable, "no-upper"); }
}
@Override
public void error(IValidatable<T> validatable, String errorKey) { ValidationError err = new ValidationError(); err.addMessageKey(Classes.simpleName(getClass()) + "." + errorKey); validatable.error(err); }
}
=============== VALIDATOR directly implementing IValidator interfce ====================
package com.mycompany;
import java.util.regex.Pattern;
import org.apache.wicket.IClusterable;
import org.apache.wicket.util.lang.Classes;
import org.apache.wicket.validation.IValidatable;
import org.apache.wicket.validation.IValidator;
import org.apache.wicket.validation.ValidationError;
import org.apache.wicket.validation.validator.AbstractValidator;
/**
*
* @author e1n
*/
public class PasswordPolicyValidator<T> implements IValidator<T> {
private static final Pattern UPPER = Pattern.compile("[A-Z]");
private static final Pattern LOWER = Pattern.compile("[a-z]");
private static final Pattern NUMBER = Pattern.compile("[0-9]");
public void validate(IValidatable<T> validatable) {
final String password = (String)validatable.getValue();
if (!NUMBER.matcher(password).find()) { error(validatable, "no-digit"); }
if (!LOWER.matcher(password).find())
{ error(validatable, "no-lower"); }if (!UPPER.matcher(password).find())
{ error(validatable, "no-upper"); }}
public void error(IValidatable<T> validatable, String errorKey)
{ ValidationError err = new ValidationError(); err.addMessageKey(Classes.simpleName(getClass()) + "." + errorKey); validatable.error(err); }}
<e1nPL> I also have properties file which is named after validator class
<e1nPL> and placed in the same package
<e1nPL> my problem is that when i use to validate my form field validator which implements IValidator interface it is not capable of loading error messages from properties file
<e1nPL> but when i am using validator which is extending AbstractValidator class
<e1nPL> properties file with error msgs gets loaded
POSSIBLE FIX:
<e1nPL> ok i have found class which is responsible for my problem and it is probably a bug
<e1nPL> org.apache.wicket.validation.ValidatorAdapter
<e1nPL> which wraps classes that directly implements IValidator interface
<e1nPL> then when resources are loaded, and properties file are searched in class path etc., loaders search in wrong path that is build against org.apache.wicket.validation.ValidatorAdapter
PLACE WHER FIX SHOULD OCCOUR
org.apache.wicket.resource.loader.ValidatorStringResourceLoader::loadStringResource(java.lang.Class,java.lang.String,java.util.Locale,java.lang.String,java.lang.String)
Attachments
Issue Links
- is duplicated by
-
WICKET-4456 Custom Validators do not lookup resources from their own .properties files
- Resolved
- relates to
-
WICKET-4234 Remove AbstractValidator because its mostly noise
- Resolved