You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by he...@apache.org on 2003/07/18 10:32:30 UTC
cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/services/intake/xmlmodel XmlField.java
henning 2003/07/18 01:32:30
Modified: src/dtd intake.dtd
xdocs changes.xml
xdocs/services intake-service.xml
src/java/org/apache/turbine/services/intake/model
BigDecimalField.java BooleanField.java
ComboKeyField.java DateStringField.java
DoubleField.java Field.java FileItemField.java
FloatField.java IntegerField.java LongField.java
ShortField.java StringField.java
StringKeyField.java
src/java/org/apache/turbine/services/intake/xmlmodel
XmlField.java
Log:
Add an "emptyValue" field to the Field classes, which makes it possible to
determine, which value should a field have that is either empty or not
returned in the form parameters. It can be set on a field base in the
intake.xml files.
Contains even documentation.
Revision Changes Path
1.8 +7 -1 jakarta-turbine-2/src/dtd/intake.dtd
Index: intake.dtd
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/dtd/intake.dtd,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- intake.dtd 19 Jun 2003 16:04:26 -0000 1.7
+++ intake.dtd 18 Jul 2003 08:32:29 -0000 1.8
@@ -106,6 +106,11 @@
Default: null
+emptyValue: Value to be used for the value of the field if it is not
+ supplied by the parameters returned from an input form.
+
+ Default: null
+
multiValued: If this is true, the field will accept multiple values.
Otherwise, the field only accepts a single vale.
@@ -169,6 +174,7 @@
mapToProperty CDATA #IMPLIED
validator CDATA #IMPLIED
defaultValue CDATA #IMPLIED
+ emptyValue CDATA #IMPLIED
>
<!--
1.58 +4 -0 jakarta-turbine-2/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/xdocs/changes.xml,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- changes.xml 15 Jul 2003 09:07:32 -0000 1.57
+++ changes.xml 18 Jul 2003 08:32:29 -0000 1.58
@@ -429,6 +429,10 @@
not only the velocity internal stack trace. You can switch this behaviour off by setting
"services.VelocityService.catch.errors" to off or false.
</li>
+ <li>
+ Intake can now assign "empty" values to fields which are not returned or left out by the browser. This
+ is useful if you want your string fields not to map to null if the user does not enter anything.
+ </li>
</ul>
</p>
</subsection>
1.7 +24 -3 jakarta-turbine-2/xdocs/services/intake-service.xml
Index: intake-service.xml
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/xdocs/services/intake-service.xml,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- intake-service.xml 9 Oct 2001 14:44:39 -0000 1.6
+++ intake-service.xml 18 Jul 2003 08:32:29 -0000 1.7
@@ -853,8 +853,8 @@
<section name="Default Values for fields">
<p>
-If you want to use input fields which should default to non-empty values,
-you can use the defaultValue field:
+If you want to use input fields which should default to non-empty values for,
+new objects, you can use the defaultValue field:
</p>
<source><![CDATA[
@@ -864,7 +864,7 @@
</group>
]]></source>
-If you set up a form like this:
+<p>If you set up a form like this:</p>
<source><![CDATA[
#if($!dz)
@@ -885,6 +885,27 @@
</p>
</section>
+
+<section name="Empty fields">
+<p>
+Sometimes you have form fields which are not required (can be left
+empty) but should be mapped onto a non null value in your bean. This
+is especially true if you use string fields in conjunction with
+"required" columns in a database. For this case, you can preset an
+"empty" value for each field which is used if a field is missing or
+empty in the form parameters returned by the browser. If you don't set
+this, the default is "null".
+</p>
+
+<source><![CDATA[
+<group name="test" key="test">
+ <field name="Value" key="val" type="String" emptyValue=""/>
+</group>
+]]></source>
+
+<p>This would return the empty String (not a null value) for the "val" field
+if the user does not enter anything. Without the emptyValue parameter, intake
+would assign the null value to the bean field.</p>
</body>
1.10 +23 -3 jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/BigDecimalField.java
Index: BigDecimalField.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/BigDecimalField.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- BigDecimalField.java 19 Jun 2003 14:56:30 -0000 1.9
+++ BigDecimalField.java 18 Jul 2003 08:32:29 -0000 1.10
@@ -105,6 +105,26 @@
}
/**
+ * Set the empty Value. This value is used if Intake
+ * maps a field to a parameter returned by the user and
+ * the corresponding field is either empty (empty string)
+ * or non-existant.
+ *
+ * @param prop The value to use if the field is empty.
+ */
+ public void setEmptyValue(String prop)
+ {
+ emptyValue = null;
+
+ if (prop == null)
+ {
+ return;
+ }
+
+ emptyValue = new BigDecimal(prop);
+ }
+
+ /**
* A suitable validator.
*
* @return A suitable validator
@@ -126,14 +146,14 @@
for (int i = 0; i < inputs.length; i++)
{
values[i] = StringUtils.isNotEmpty(inputs[i])
- ? canonicalizeDecimalInput(inputs[i]) : null;
+ ? canonicalizeDecimalInput(inputs[i]) : (BigDecimal) getEmptyValue();
}
setTestValue(values);
}
else
{
String val = parser.getString(getKey());
- setTestValue(StringUtils.isNotEmpty(val) ? canonicalizeDecimalInput(val) : null);
+ setTestValue(StringUtils.isNotEmpty(val) ? canonicalizeDecimalInput(val) : (BigDecimal) getEmptyValue());
}
}
1.10 +23 -3 jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/BooleanField.java
Index: BooleanField.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/BooleanField.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- BooleanField.java 18 Jul 2003 08:16:45 -0000 1.9
+++ BooleanField.java 18 Jul 2003 08:32:29 -0000 1.10
@@ -103,6 +103,26 @@
}
/**
+ * Set the empty Value. This value is used if Intake
+ * maps a field to a parameter returned by the user and
+ * the corresponding field is either empty (empty string)
+ * or non-existant.
+ *
+ * @param prop The value to use if the field is empty.
+ */
+ public void setEmptyValue(String prop)
+ {
+ emptyValue = null;
+
+ if (prop == null)
+ {
+ return;
+ }
+
+ emptyValue = new Boolean(prop);
+ }
+
+ /**
* A suitable validator.
*
* @return class name of the validator
@@ -124,14 +144,14 @@
for (int i = 0; i < inputs.length; i++)
{
values[i] = StringUtils.isNotEmpty(inputs[i])
- ? getBoolean(inputs[i]) : null;
+ ? getBoolean(inputs[i]) : (Boolean) getEmptyValue();
}
setTestValue(values);
}
else
{
String val = parser.getString(getKey());
- setTestValue(StringUtils.isNotEmpty(val) ? getBoolean(val) : null);
+ setTestValue(StringUtils.isNotEmpty(val) ? getBoolean(val) : (Boolean) getEmptyValue());
}
}
1.11 +23 -3 jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/ComboKeyField.java
Index: ComboKeyField.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/ComboKeyField.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ComboKeyField.java 19 Jun 2003 14:58:49 -0000 1.10
+++ ComboKeyField.java 18 Jul 2003 08:32:29 -0000 1.11
@@ -101,6 +101,26 @@
}
/**
+ * Set the empty Value. This value is used if Intake
+ * maps a field to a parameter returned by the user and
+ * the corresponding field is either empty (empty string)
+ * or non-existant.
+ *
+ * @param prop The value to use if the field is empty.
+ */
+ public void setEmptyValue(String prop)
+ {
+ emptyValue = null;
+
+ if (prop == null)
+ {
+ return;
+ }
+
+ emptyValue = new ComboKey(prop);
+ }
+
+ /**
* Sets the value of the field from data in the parser.
*/
protected void doSetValue()
@@ -112,14 +132,14 @@
for (int i = 0; i < inputs.length; i++)
{
values[i] = StringUtils.isNotEmpty(inputs[i])
- ? new ComboKey(inputs[i]) : null;
+ ? new ComboKey(inputs[i]) : (ComboKey) getEmptyValue();
}
setTestValue(values);
}
else
{
String val = parser.getString(getKey());
- setTestValue(StringUtils.isNotEmpty(val) ? new ComboKey(val) : null);
+ setTestValue(StringUtils.isNotEmpty(val) ? new ComboKey(val) : (ComboKey) getEmptyValue());
}
}
}
1.9 +32 -4 jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/DateStringField.java
Index: DateStringField.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/DateStringField.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DateStringField.java 19 Jun 2003 14:58:49 -0000 1.8
+++ DateStringField.java 18 Jul 2003 08:32:30 -0000 1.9
@@ -122,7 +122,35 @@
catch (ParseException e)
{
throw new TurbineRuntimeException("Could not parse " + prop
- + " into a valid Date", e);
+ + " into a valid Date for the default value", e);
+ }
+ }
+
+ /**
+ * Set the empty Value. This value is used if Intake
+ * maps a field to a parameter returned by the user and
+ * the corresponding field is either empty (empty string)
+ * or non-existant.
+ *
+ * @param prop The value to use if the field is empty.
+ */
+ public void setEmptyValue(String prop)
+ {
+ emptyValue = null;
+
+ if (prop == null)
+ {
+ return;
+ }
+
+ try
+ {
+ emptyValue = getDate(prop);
+ }
+ catch (ParseException e)
+ {
+ throw new TurbineRuntimeException("Could not parse " + prop
+ + " into a valid Date for the empty value", e);
}
}
@@ -150,7 +178,7 @@
try
{
values[i] = StringUtils.isNotEmpty(inputs[i])
- ? getDate(inputs[i]) : null;
+ ? getDate(inputs[i]) : (Date) getEmptyValue();
}
catch (ParseException e)
{
@@ -164,7 +192,7 @@
String val = parser.getString(getKey());
try
{
- setTestValue(StringUtils.isNotEmpty(val) ? getDate(val) : null);
+ setTestValue(StringUtils.isNotEmpty(val) ? getDate(val) : (Date) getEmptyValue());
}
catch (ParseException e)
{
1.7 +23 -3 jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/DoubleField.java
Index: DoubleField.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/DoubleField.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DoubleField.java 19 Jun 2003 14:56:30 -0000 1.6
+++ DoubleField.java 18 Jul 2003 08:32:30 -0000 1.7
@@ -100,6 +100,26 @@
}
/**
+ * Set the empty Value. This value is used if Intake
+ * maps a field to a parameter returned by the user and
+ * the corresponding field is either empty (empty string)
+ * or non-existant.
+ *
+ * @param prop The value to use if the field is empty.
+ */
+ public void setEmptyValue(String prop)
+ {
+ emptyValue = null;
+
+ if (prop == null)
+ {
+ return;
+ }
+
+ emptyValue = new Double(prop);
+ }
+
+ /**
* A suitable validator.
*
* @return A suitable validator
@@ -121,14 +141,14 @@
for (int i = 0; i < inputs.length; i++)
{
values[i] = StringUtils.isNotEmpty(inputs[i])
- ? new Double(inputs[i]) : null;
+ ? new Double(inputs[i]) : (Double) getEmptyValue();
}
setTestValue(values);
}
else
{
String val = parser.getString(getKey());
- setTestValue(StringUtils.isNotEmpty(val) ? new Double(val) : null);
+ setTestValue(StringUtils.isNotEmpty(val) ? new Double(val) : (Double) getEmptyValue());
}
}
}
1.13 +28 -2 jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/Field.java
Index: Field.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/Field.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Field.java 15 Jul 2003 10:15:18 -0000 1.12
+++ Field.java 18 Jul 2003 08:32:30 -0000 1.13
@@ -144,6 +144,9 @@
/** Default value of the field */
protected Object defaultValue;
+ /** Value of the field to use if the mapped parameter is empty or non-existant */
+ protected Object emptyValue;
+
/** Display size of the field */
private String displaySize;
@@ -674,11 +677,24 @@
}
/**
- * Set the default Value.
+ * Set the default Value. This value is used if
+ * Intake should map this field to a new object.
+ *
+ * @param prop The value to use if the field is mapped to a new object.
*/
public abstract void setDefaultValue(String prop);
/**
+ * Set the empty Value. This value is used if Intake
+ * maps a field to a parameter returned by the user and
+ * the corresponding field is either empty (empty string)
+ * or non-existant.
+ *
+ * @param prop The value to use if the field is empty.
+ */
+ public abstract void setEmptyValue(String prop);
+
+ /**
* @deprecated Use doSetValue() instead (with no parameters).
*/
protected void doSetValue(ValueParser pp)
@@ -928,6 +944,16 @@
public Object getDefaultValue()
{
return defaultValue;
+ }
+
+ /**
+ * Get the Value to use if the field is empty
+ *
+ * @return the value to use if the field is empty.
+ */
+ public Object getEmptyValue()
+ {
+ return emptyValue;
}
/**
1.13 +21 -1 jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/FileItemField.java
Index: FileItemField.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/FileItemField.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- FileItemField.java 9 May 2003 11:09:52 -0000 1.12
+++ FileItemField.java 18 Jul 2003 08:32:30 -0000 1.13
@@ -108,6 +108,26 @@
}
/**
+ * It is not possible to set the empty value for this field type.
+ * Calling this method with a non-null parameter will result in a
+ * TurbineRuntimeException
+ *
+ * @param prop Parameter for the empty values
+ * @throws TurbineRuntimeException
+ */
+ public void setEmptyValue(String prop)
+ {
+ if (prop != null)
+ {
+ throw new TurbineRuntimeException(
+ "Empty values are not valid for "
+ + this.getClass().getName());
+ }
+
+ emptyValue = null;
+ }
+
+ /**
* A suitable validator.
*
* @return A suitable validator
1.9 +23 -3 jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/FloatField.java
Index: FloatField.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/FloatField.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FloatField.java 19 Jun 2003 14:56:30 -0000 1.8
+++ FloatField.java 18 Jul 2003 08:32:30 -0000 1.9
@@ -104,6 +104,26 @@
}
/**
+ * Set the empty Value. This value is used if Intake
+ * maps a field to a parameter returned by the user and
+ * the corresponding field is either empty (empty string)
+ * or non-existant.
+ *
+ * @param prop The value to use if the field is empty.
+ */
+ public void setEmptyValue(String prop)
+ {
+ emptyValue = null;
+
+ if (prop == null)
+ {
+ return;
+ }
+
+ emptyValue = new Double(prop);
+ }
+
+ /**
* A suitable validator.
*
* @return A suitable validator
@@ -125,14 +145,14 @@
for (int i = 0; i < inputs.length; i++)
{
values[i] = StringUtils.isNotEmpty(inputs[i])
- ? new Float(inputs[i]) : null;
+ ? new Float(inputs[i]) : (Float) getEmptyValue();
}
setTestValue(values);
}
else
{
String val = parser.getString(getKey());
- setTestValue(StringUtils.isNotEmpty(val) ? new Float(val) : null);
+ setTestValue(StringUtils.isNotEmpty(val) ? new Float(val) : getEmptyValue());
}
}
}
1.10 +23 -3 jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/IntegerField.java
Index: IntegerField.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/IntegerField.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- IntegerField.java 19 Jun 2003 14:58:49 -0000 1.9
+++ IntegerField.java 18 Jul 2003 08:32:30 -0000 1.10
@@ -101,6 +101,26 @@
}
/**
+ * Set the empty Value. This value is used if Intake
+ * maps a field to a parameter returned by the user and
+ * the corresponding field is either empty (empty string)
+ * or non-existant.
+ *
+ * @param prop The value to use if the field is empty.
+ */
+ public void setEmptyValue(String prop)
+ {
+ emptyValue = null;
+
+ if (prop == null)
+ {
+ return;
+ }
+
+ emptyValue = new Integer(prop);
+ }
+
+ /**
* A suitable validator.
*
* @return A suitable validator
@@ -122,14 +142,14 @@
for (int i = 0; i < inputs.length; i++)
{
values[i] = StringUtils.isNotEmpty(inputs[i])
- ? new Integer(inputs[i]) : null;
+ ? new Integer(inputs[i]) : (Integer) getEmptyValue();
}
setTestValue(values);
}
else
{
String val = parser.getString(getKey());
- setTestValue(StringUtils.isNotEmpty(val) ? new Integer(val) : null);
+ setTestValue(StringUtils.isNotEmpty(val) ? new Integer(val) : (Integer) getEmptyValue());
}
}
}
1.3 +23 -3 jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/LongField.java
Index: LongField.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/LongField.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LongField.java 18 Jul 2003 08:19:37 -0000 1.2
+++ LongField.java 18 Jul 2003 08:32:30 -0000 1.3
@@ -102,6 +102,26 @@
}
/**
+ * Set the empty Value. This value is used if Intake
+ * maps a field to a parameter returned by the user and
+ * the corresponding field is either empty (empty string)
+ * or non-existant.
+ *
+ * @param prop The value to use if the field is empty.
+ */
+ public void setEmptyValue(String prop)
+ {
+ emptyValue = null;
+
+ if (prop == null)
+ {
+ return;
+ }
+
+ emptyValue = new Long(prop);
+ }
+
+ /**
* A suitable validator.
*
* @return A suitable validator
@@ -123,14 +143,14 @@
for (int i = 0; i < inputs.length; i++)
{
values[i] = StringUtils.isNotEmpty(inputs[i])
- ? new Long(inputs[i]) : null;
+ ? new Long(inputs[i]) : (Long) getEmptyValue();
}
setTestValue(values);
}
else
{
String val = parser.getString(getKey());
- setTestValue(StringUtils.isNotEmpty(val) ? new Long(val) : null);
+ setTestValue(StringUtils.isNotEmpty(val) ? new Long(val) : (Long) getEmptyValue());
}
}
}
1.3 +23 -3 jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/ShortField.java
Index: ShortField.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/ShortField.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ShortField.java 18 Jul 2003 08:19:37 -0000 1.2
+++ ShortField.java 18 Jul 2003 08:32:30 -0000 1.3
@@ -102,6 +102,26 @@
}
/**
+ * Set the empty Value. This value is used if Intake
+ * maps a field to a parameter returned by the user and
+ * the corresponding field is either empty (empty string)
+ * or non-existant.
+ *
+ * @param prop The value to use if the field is empty.
+ */
+ public void setEmptyValue(String prop)
+ {
+ emptyValue = null;
+
+ if (prop == null)
+ {
+ return;
+ }
+
+ emptyValue = new Short(prop);
+ }
+
+ /**
* A suitable validator.
*
* @return A suitable validator
@@ -123,14 +143,14 @@
for (int i = 0; i < inputs.length; i++)
{
values[i] = StringUtils.isNotEmpty(inputs[i])
- ? new Short(inputs[i]) : null;
+ ? new Short(inputs[i]) : (Short) getEmptyValue();
}
setTestValue(values);
}
else
{
String val = parser.getString(getKey());
- setTestValue(StringUtils.isNotEmpty(val) ? new Short(val) : null);
+ setTestValue(StringUtils.isNotEmpty(val) ? new Short(val) : (Short) getEmptyValue());
}
}
}
1.10 +16 -3 jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/StringField.java
Index: StringField.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/StringField.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- StringField.java 15 Jul 2003 10:13:57 -0000 1.9
+++ StringField.java 18 Jul 2003 08:32:30 -0000 1.10
@@ -106,6 +106,19 @@
}
/**
+ * Set the empty Value. This value is used if Intake
+ * maps a field to a parameter returned by the user and
+ * the corresponding field is either empty (empty string)
+ * or non-existant.
+ *
+ * @param prop The value to use if the field is empty.
+ */
+ public void setEmptyValue(String prop)
+ {
+ emptyValue = prop;
+ }
+
+ /**
* Sets the value of the field from data in the parser.
*/
protected void doSetValue()
@@ -116,14 +129,14 @@
String[] sval = new String[ss.length];
for (int i = 0; i < ss.length; i++)
{
- sval[i] = (StringUtils.isNotEmpty(ss[i])) ? ss[i] : "";
+ sval[i] = (StringUtils.isNotEmpty(ss[i])) ? ss[i] : (String) getEmptyValue();
}
setTestValue(sval);
}
else
{
String val = parser.getString(getKey());
- setTestValue(StringUtils.isNotEmpty(val) ? val : "");
+ setTestValue(StringUtils.isNotEmpty(val) ? val : (String) getEmptyValue());
}
}
1.11 +21 -3 jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/StringKeyField.java
Index: StringKeyField.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/StringKeyField.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- StringKeyField.java 19 Jun 2003 14:56:30 -0000 1.10
+++ StringKeyField.java 18 Jul 2003 08:32:30 -0000 1.11
@@ -112,6 +112,24 @@
}
/**
+ * Set the empty Value. This value is used if Intake
+ * maps a field to a parameter returned by the user and
+ * the corresponding field is either empty (empty string)
+ * or non-existant.
+ *
+ * @param prop The value to use if the field is empty.
+ */
+ public void setEmptyValue(String prop)
+ {
+ if (prop == null)
+ {
+ return;
+ }
+
+ emptyValue = new StringKey(prop);
+ }
+
+ /**
* Sets the value of the field from data in the parser.
*/
protected void doSetValue()
@@ -123,7 +141,7 @@
for (int i = 0; i < ss.length; i++)
{
ival[i] = (StringUtils.isNotEmpty(ss[i]))
- ? new StringKey(ss[i]) : null;
+ ? new StringKey(ss[i]) : (StringKey) getEmptyValue();
}
setTestValue(ival);
}
@@ -131,7 +149,7 @@
{
String val = parser.getString(getKey());
setTestValue((StringUtils.isNotEmpty(val))
- ? new StringKey(val) : null);
+ ? new StringKey(val) : (StringKey) getEmptyValue());
}
}
}
1.9 +28 -1 jakarta-turbine-2/src/java/org/apache/turbine/services/intake/xmlmodel/XmlField.java
Index: XmlField.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/intake/xmlmodel/XmlField.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- XmlField.java 7 Apr 2003 15:30:51 -0000 1.8
+++ XmlField.java 18 Jul 2003 08:32:30 -0000 1.9
@@ -93,6 +93,7 @@
private String mapToProperty;
private String validator;
private String defaultValue;
+ private String emptyValue;
private String displaySize;
/**
@@ -135,6 +136,7 @@
setMapToProperty(attrib.getValue("mapToProperty"));
setValidator(attrib.getValue("validator"));
setDefaultValue(attrib.getValue("defaultValue"));
+ setDefaultValue(attrib.getValue("emptyValue"));
}
/**
@@ -326,6 +328,26 @@
}
/**
+ * Set the empty Value.
+ *
+ * @param prop The parameter to use as empty value.
+ */
+ public void setEmptyValue(String prop)
+ {
+ emptyValue = prop;
+ }
+
+ /**
+ * Get the empty Value.
+ *
+ * @return The empty value for this field.
+ */
+ public String getEmptyValue()
+ {
+ return emptyValue;
+ }
+
+ /**
* The name of the field making sure the first letter is lowercase.
*
* @return a <code>String</code> value
@@ -452,6 +474,11 @@
if (defaultValue != null)
{
result.append(" defaultValue=\"" + defaultValue + "\"");
+ }
+
+ if (emptyValue != null)
+ {
+ result.append(" emptyValue=\"" + emptyValue + "\"");
}
if (rules.size() == 0)
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org