> From: John McNally <[EMAIL PROTECTED]>
>
> I removed the
>
> > > > > if ( stringValue.length() == 0 )
> > > > > {
> > > > > set_flag = false;
> > > > > }
>
> code that you mentioned from Field and moved it to some of the number
> fields where i think it is still needed. This is checked into the head
> of the fulcrum repo. Sorry, I forgot to give notice. Please let me
> know if this helps your situation.
>
> john mcnally
Sorry for my slowness in following up on this. Pressure of work...
On reflection, it seems to me that of all the field types in
Intake it is only for String fields that it makes immediate
sense that the field could be "set but empty", so pushing
the above test down into all the other Field subclasses
seems awkward. Instead what I've done is to add a
method, valueCanBeEmpty(), which acts as a gatekeeper for
emtpy-string values, and returns false by default, only
being overriden to true in StringField.
The other issue is that the fix as it is means that an empty
String input will go through intake as the empty string, "",
rather than null. This is going to break a lot of existing
systems (it certainly broke ours :-). So I've modified
StringField so that an empty string as the String input will
set the testValue to null (but be regarded as "set").
This is all still a bit of a hack, but the Intake code is
beginning to look a bit hairy anyway, so the attached patch
should feel at home. ;-)
Regards,
William
? field.patch
? src/java/org/apache/fulcrum/intake/model/.Field.java.swp
? src/java/org/apache/fulcrum/intake/model/.StringField.java.swp
Index: src/java/org/apache/fulcrum/intake/model/Field.java
===================================================================
RCS file:
/home/cvspublic/jakarta-turbine-fulcrum/src/java/org/apache/fulcrum/intake/model/Field.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Field.java
--- src/java/org/apache/fulcrum/intake/model/Field.java 30 May 2002 02:27:18 -0000
1.1.1.1
+++ src/java/org/apache/fulcrum/intake/model/Field.java 12 Jun 2002 05:32:40 -0000
@@ -499,6 +499,11 @@
else
{
stringValue = pp.getString(getKey());
+ if (stringValue.length() == 0 && !valueCanBeEmpty())
+ {
+ set_flag = false;
+ }
+
if ( validator != null )
{
// set the test value as a String which might be replaced by
@@ -526,6 +531,19 @@
}
return valid_flag;
+ }
+
+ /**
+ * Is an empty value allowable?.
+ * This is a value that comes in from the parameters as an empty string,
+ * not one that is not present in the parameters. By default, this
+ * will be counted as "not set", but subclasses can chose to allow
+ * this to be counted as "set" by overriding this method and returning
+ * true.
+ */
+ protected boolean valueCanBeEmpty()
+ {
+ return false;
}
/**
Index: src/java/org/apache/fulcrum/intake/model/StringField.java
===================================================================
RCS file:
/home/cvspublic/jakarta-turbine-fulcrum/src/java/org/apache/fulcrum/intake/model/StringField.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 StringField.java
--- src/java/org/apache/fulcrum/intake/model/StringField.java 30 May 2002 02:27:19
-0000 1.1.1.1
+++ src/java/org/apache/fulcrum/intake/model/StringField.java 12 Jun 2002 05:32:40
+-0000
@@ -83,7 +83,11 @@
}
else
{
- setTestValue(pp.getString(getKey()));
+ String s = pp.getString(getKey());
+ if (s.length() == 0)
+ setTestValue(null);
+ else
+ setTestValue(s);
}
}
@@ -123,7 +127,8 @@
}
else
{
- if (!set_flag || ((String)getTestValue()).length() == 0)
+ String s = (String) getTestValue();
+ if (!set_flag || s == null || s.length() == 0)
{
valid_flag = false;
this.message = message;
@@ -131,5 +136,12 @@
}
}
+ }
+
+ /**
+ * Allow empty string as a valid value.
+ */
+ protected boolean valueCanBeEmpty() {
+ return true;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>