-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
1.4.1
-
x86
-
windows_xp
Name: jk109818 Date: 07/01/2003
A DESCRIPTION OF THE REQUEST :
The MaskFormatter requires completion of the entire mask for the data to be considered valid. My request is similar to 4722419 in that I'd like the ability to not require a full entry of the mask for it to be considered valid. I'm not concerned about specifying the length of input, just whether or not incomplete entry is allowed.
If the underlying code was at all extensible, this would be a non-issue and I could write the code myself. Currently, to enable this functionality, I have had to create my own copy of MaskFormatter and DefaultFormatter. Both classes contain many private methods and classes that inhibit extension. My DefaultFormatter is identical to Sun's version. My MaskFormatter only replaces the stringToValue(String) method as follows:
public Object stringToValue(String value) throws ParseException {
// Sun's way
// return stringToValue(value, true);
// My way
return stringToValue(value, !acceptPartialInput); // my new boolean variable
}
I also had to replace the append() method of the MaskCharacter (private) internal class. My version doesn't throw a parse exception if the character is a literal or matches the placeholder character.
In this fashion, my problem has been solved, but I've ended up with 2 new class implementations when I only needed to override a few methods.
JUSTIFICATION :
As mentioned in the problem description, the underlying code is not at all extensible. It's highly unlikely that Sun provides a solution to meet the needs of all, but at the least, it seems reasonable to expect the ability to extend and customize as needed. Cut & paste inheritance, though fine on the productivity scale, doesn't result in a manageable code base.
CUSTOMER SUBMITTED WORKAROUND :
This code is my modification to the internal MaskCharacter class of the MaskFormatter. This limits the throwing of parse exceptions.
public void append(StringBuffer buff, String formatting, int[] index,
String placeholder) throws ParseException {
boolean inString = index[0] < formatting.length();
char aChar = inString ? formatting.charAt(index[0]) : 0;
if (isLiteral()) {
buff.append(getChar(aChar));
if (getValueContainsLiteralCharacters()) {
index[0]++;
}
}
else if (index[0] >= formatting.length()) {
if (placeholder != null && index[0] < placeholder.length()) {
buff.append(placeholder.charAt(index[0]));
}
else {
buff.append(getPlaceholderCharacter());
}
index[0]++;
}
else if (isValidCharacter(aChar)) {
buff.append(getChar(aChar));
index[0]++;
}
else if (aChar != getPlaceholderCharacter()) {
throw new ParseException("Invalid character: " + aChar,
index[0]);
} else {
buff.append(aChar);
index[0]++;
}
}
}
(Review ID: 189352)
======================================================================
A DESCRIPTION OF THE REQUEST :
The MaskFormatter requires completion of the entire mask for the data to be considered valid. My request is similar to 4722419 in that I'd like the ability to not require a full entry of the mask for it to be considered valid. I'm not concerned about specifying the length of input, just whether or not incomplete entry is allowed.
If the underlying code was at all extensible, this would be a non-issue and I could write the code myself. Currently, to enable this functionality, I have had to create my own copy of MaskFormatter and DefaultFormatter. Both classes contain many private methods and classes that inhibit extension. My DefaultFormatter is identical to Sun's version. My MaskFormatter only replaces the stringToValue(String) method as follows:
public Object stringToValue(String value) throws ParseException {
// Sun's way
// return stringToValue(value, true);
// My way
return stringToValue(value, !acceptPartialInput); // my new boolean variable
}
I also had to replace the append() method of the MaskCharacter (private) internal class. My version doesn't throw a parse exception if the character is a literal or matches the placeholder character.
In this fashion, my problem has been solved, but I've ended up with 2 new class implementations when I only needed to override a few methods.
JUSTIFICATION :
As mentioned in the problem description, the underlying code is not at all extensible. It's highly unlikely that Sun provides a solution to meet the needs of all, but at the least, it seems reasonable to expect the ability to extend and customize as needed. Cut & paste inheritance, though fine on the productivity scale, doesn't result in a manageable code base.
CUSTOMER SUBMITTED WORKAROUND :
This code is my modification to the internal MaskCharacter class of the MaskFormatter. This limits the throwing of parse exceptions.
public void append(StringBuffer buff, String formatting, int[] index,
String placeholder) throws ParseException {
boolean inString = index[0] < formatting.length();
char aChar = inString ? formatting.charAt(index[0]) : 0;
if (isLiteral()) {
buff.append(getChar(aChar));
if (getValueContainsLiteralCharacters()) {
index[0]++;
}
}
else if (index[0] >= formatting.length()) {
if (placeholder != null && index[0] < placeholder.length()) {
buff.append(placeholder.charAt(index[0]));
}
else {
buff.append(getPlaceholderCharacter());
}
index[0]++;
}
else if (isValidCharacter(aChar)) {
buff.append(getChar(aChar));
index[0]++;
}
else if (aChar != getPlaceholderCharacter()) {
throw new ParseException("Invalid character: " + aChar,
index[0]);
} else {
buff.append(aChar);
index[0]++;
}
}
}
(Review ID: 189352)
======================================================================