Author: hlship
Date: Wed Dec 7 13:14:42 2005
New Revision: 354862
URL: http://svn.apache.org/viewcvs?rev=354862&view=rev
Log:
TAPESTRY-658: LabeledPropertySelectionModel throws NPE on null value
Added:
jakarta/tapestry/branches/4.0/framework/src/test/org/apache/tapestry/form/LabeledPropertySelectionModelTest.java
- copied, changed from r354478,
jakarta/tapestry/branches/4.0/framework/src/test/org/apache/tapestry/form/TestLabeledPropertySelectionModel.java
Removed:
jakarta/tapestry/branches/4.0/framework/src/test/org/apache/tapestry/form/TestLabeledPropertySelectionModel.java
Modified:
jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/form/LabeledPropertySelectionModel.java
jakarta/tapestry/branches/4.0/status.xml
Modified:
jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/form/LabeledPropertySelectionModel.java
URL:
http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/form/LabeledPropertySelectionModel.java?rev=354862&r1=354861&r2=354862&view=diff
==============================================================================
---
jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/form/LabeledPropertySelectionModel.java
(original)
+++
jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/form/LabeledPropertySelectionModel.java
Wed Dec 7 13:14:42 2005
@@ -15,9 +15,8 @@
package org.apache.tapestry.form;
/**
- * Decorates an underlying [EMAIL PROTECTED] IPropertySelectionModel}adding an
initial
- * property. The label, option, and value of the initial property are
- * configurable.
+ * Decorates an underlying [EMAIL PROTECTED] IPropertySelectionModel}adding an
initial property. The label,
+ * option, and value of the initial property are configurable.
*
* @author Paul Ferraro
* @since 4.0
@@ -25,14 +24,17 @@
public class LabeledPropertySelectionModel implements IPropertySelectionModel
{
private IPropertySelectionModel _model;
+
private String _label = "";
+
private Object _option = null;
+
private String _value = "";
/**
- * Constructs a new LabeledPropertySelectionModel using an empty model and
- * default label, option, and value. Default constructor is made available
- * so that this model may be specified as a component helper bean.
+ * Constructs a new LabeledPropertySelectionModel using an empty model and
default label,
+ * option, and value. Default constructor is made available so that this
model may be specified
+ * as a component helper bean.
*/
public LabeledPropertySelectionModel()
{
@@ -40,9 +42,11 @@
}
/**
- * Constructs a new LabeledPropertySelectionModel using the specified model
- * and default label, option, and value.
- * @param model the underlying model to decorate
+ * Constructs a new LabeledPropertySelectionModel using the specified
model and default label,
+ * option, and value.
+ *
+ * @param model
+ * the underlying model to decorate
*/
public LabeledPropertySelectionModel(IPropertySelectionModel model)
{
@@ -50,13 +54,15 @@
}
/**
- * Constructs a new LabeledPropertySelectionModel using the specified model
- * and label, and default option and value.
- * @param model the underlying model to decorate
- * @param label the label of the initial property
+ * Constructs a new LabeledPropertySelectionModel using the specified
model and label, and
+ * default option and value.
+ *
+ * @param model
+ * the underlying model to decorate
+ * @param label
+ * the label of the initial property
*/
- public LabeledPropertySelectionModel(IPropertySelectionModel model,
- String label)
+ public LabeledPropertySelectionModel(IPropertySelectionModel model, String
label)
{
this(model);
@@ -64,14 +70,17 @@
}
/**
- * Constructs a new LabeledPropertySelectionModel using the specified
model,
- * label, and option; and default value.
- * @param model the underlying model to decorate
- * @param label the label of the initial property
- * @param option the option value of the initial property
+ * Constructs a new LabeledPropertySelectionModel using the specified
model, label, and option;
+ * and default value.
+ *
+ * @param model
+ * the underlying model to decorate
+ * @param label
+ * the label of the initial property
+ * @param option
+ * the option value of the initial property
*/
- public LabeledPropertySelectionModel(IPropertySelectionModel model,
- String label, Object option)
+ public LabeledPropertySelectionModel(IPropertySelectionModel model, String
label, Object option)
{
this(model, label);
@@ -79,15 +88,20 @@
}
/**
- * Constructs a new LabeledPropertySelectionModel using the specified
model,
- * label, option, and value.
- * @param model the underlying model to decorate
- * @param label the label of the initial property
- * @param option the option value of the initial property
- * @param value the value of the initial property
+ * Constructs a new LabeledPropertySelectionModel using the specified
model, label, option, and
+ * value.
+ *
+ * @param model
+ * the underlying model to decorate
+ * @param label
+ * the label of the initial property
+ * @param option
+ * the option value of the initial property
+ * @param value
+ * the value of the initial property
*/
- public LabeledPropertySelectionModel(IPropertySelectionModel model,
- String label, Object option, String value)
+ public LabeledPropertySelectionModel(IPropertySelectionModel model, String
label,
+ Object option, String value)
{
this(model, label, option);
@@ -96,22 +110,25 @@
/**
* Returns the underlying IPropertySelectionModel
+ *
* @return the underlying IPropertySelectionModel
*/
public IPropertySelectionModel getModel()
{
return _model;
}
-
+
/**
* Sets the underlying IPropertySelectionModel
- * @param model the IPropertySelectionModel to set
+ *
+ * @param model
+ * the IPropertySelectionModel to set
*/
public void setModel(IPropertySelectionModel model)
{
_model = model;
}
-
+
/**
* @see org.apache.tapestry.form.IPropertySelectionModel#getOptionCount()
*/
@@ -149,11 +166,15 @@
*/
public Object translateValue(String value)
{
+ if (value == null)
+ return null;
+
return value.equals(_value) ? _option : _model.translateValue(value);
}
/**
* Returns the label of the initial IPropertySelectionModel option
+ *
* @return a IPropertySelectionModel option label
*/
public String getLabel()
@@ -163,7 +184,9 @@
/**
* Sets the label of the initial IPropertySelectionModel option
- * @param label a IPropertySelectionModel option label
+ *
+ * @param label
+ * a IPropertySelectionModel option label
*/
public void setLabel(String label)
{
@@ -172,6 +195,7 @@
/**
* Returns the value of the initial IPropertySelectionModel option
+ *
* @return a IPropertySelectionModel option value
*/
public String getValue()
@@ -181,7 +205,9 @@
/**
* Sets the value of the initial IPropertySelectionModel option
- * @param value a IPropertySelectionModel option value
+ *
+ * @param value
+ * a IPropertySelectionModel option value
*/
public void setValue(String value)
{
@@ -190,6 +216,7 @@
/**
* Returns the initial option
+ *
* @return a PropertySelectionModel option
*/
public Object getOption()
@@ -199,7 +226,9 @@
/**
* Sets the initial IPropertySelectionModel option
- * @param option a IPropertySelectionModel option
+ *
+ * @param option
+ * a IPropertySelectionModel option
*/
public void setOption(Object option)
{
@@ -207,8 +236,7 @@
}
/**
- * Empty model implementation. Avoids NullPointerExceptions when default
- * constructor is used.
+ * Empty model implementation. Avoids NullPointerExceptions when default
constructor is used.
*/
private static final IPropertySelectionModel EMPTY_MODEL = new
IPropertySelectionModel()
{
Copied:
jakarta/tapestry/branches/4.0/framework/src/test/org/apache/tapestry/form/LabeledPropertySelectionModelTest.java
(from r354478,
jakarta/tapestry/branches/4.0/framework/src/test/org/apache/tapestry/form/TestLabeledPropertySelectionModel.java)
URL:
http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/framework/src/test/org/apache/tapestry/form/LabeledPropertySelectionModelTest.java?p2=jakarta/tapestry/branches/4.0/framework/src/test/org/apache/tapestry/form/LabeledPropertySelectionModelTest.java&p1=jakarta/tapestry/branches/4.0/framework/src/test/org/apache/tapestry/form/TestLabeledPropertySelectionModel.java&r1=354478&r2=354862&rev=354862&view=diff
==============================================================================
---
jakarta/tapestry/branches/4.0/framework/src/test/org/apache/tapestry/form/TestLabeledPropertySelectionModel.java
(original)
+++
jakarta/tapestry/branches/4.0/framework/src/test/org/apache/tapestry/form/LabeledPropertySelectionModelTest.java
Wed Dec 7 13:14:42 2005
@@ -14,33 +14,38 @@
package org.apache.tapestry.form;
-import org.apache.tapestry.form.IPropertySelectionModel;
-import org.apache.tapestry.form.LabeledPropertySelectionModel;
-import org.apache.tapestry.junit.TapestryTestCase;
+import junit.framework.TestCase;
/**
* Test case for [EMAIL PROTECTED]
org.apache.tapestry.form.LabeledPropertySelectionModel}.
*
* @author Paul Ferraro
- * @since 4.0
+ * @since 4.0
*/
-public class TestLabeledPropertySelectionModel extends TapestryTestCase
+public class LabeledPropertySelectionModelTest extends TestCase
{
+ public void testNullValue()
+ {
+ LabeledPropertySelectionModel model = new
LabeledPropertySelectionModel();
+
+ assertEquals(null, model.translateValue(null));
+ }
+
public void testEmptyModel()
{
LabeledPropertySelectionModel model = new
LabeledPropertySelectionModel();
-
+
validateLabel(model, "", null, "");
-
+
assertEquals(model.getOptionCount(), 1);
}
-
+
public void testDefaultLabeledModel()
{
LabeledPropertySelectionModel model = new
LabeledPropertySelectionModel(createInnerModel());
-
+
validateLabel(model, "", null, "");
-
+
validateModel(model);
}
@@ -49,32 +54,34 @@
String label = "Select a value";
Object option = null;
String value = "-1";
-
- LabeledPropertySelectionModel model = new
LabeledPropertySelectionModel(createInnerModel(), label, option, value);
-
+
+ LabeledPropertySelectionModel model = new
LabeledPropertySelectionModel(createInnerModel(),
+ label, option, value);
+
assertEquals(label, model.getLabel());
assertEquals(option, model.getOption());
assertEquals(value, model.getValue());
-
+
validateLabel(model, label, option, value);
-
+
validateModel(model);
}
-
- private void validateLabel(IPropertySelectionModel model, String label,
Object option, String value)
+
+ private void validateLabel(IPropertySelectionModel model, String label,
Object option,
+ String value)
{
assertTrue(model.getOptionCount() > 0);
-
+
assertEquals(model.getLabel(0), label);
assertEquals(model.getOption(0), option);
assertEquals(model.getValue(0), value);
assertEquals(model.translateValue(value), option);
}
-
+
private void validateModel(IPropertySelectionModel model)
{
assertEquals(model.getOptionCount(), 3);
-
+
assertEquals(model.getLabel(1), "true");
assertEquals(model.getOption(1), Boolean.TRUE);
assertEquals(model.getValue(1), "0");
@@ -85,13 +92,14 @@
assertEquals(model.getValue(2), "1");
assertEquals(model.translateValue("1"), Boolean.FALSE);
}
-
+
private IPropertySelectionModel createInnerModel()
{
return new IPropertySelectionModel()
{
- private boolean[] values = new boolean[] { true, false };
-
+ private boolean[] values = new boolean[]
+ { true, false };
+
public int getOptionCount()
{
return values.length;
Modified: jakarta/tapestry/branches/4.0/status.xml
URL:
http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/status.xml?rev=354862&r1=354861&r2=354862&view=diff
==============================================================================
--- jakarta/tapestry/branches/4.0/status.xml (original)
+++ jakarta/tapestry/branches/4.0/status.xml Wed Dec 7 13:14:42 2005
@@ -56,6 +56,7 @@
<changes>
<release version="4.0" date="unreleased">
<action type="fix" dev="HLS"
fixes-bug="TAPESTRY-789">DefaultResourceLocalizerTest is under framework/src
not framework/test</action>
+ <action type="fix" dev="HLS" fixes-bug="TAPESTRY-658" due=to="Leonardo
Quijano Vincenzi">LabeledPropertySelectionModel throws NPE on null
value</action>
</release>
<release version="4.0-rc-1" date="Dec 6 2005">
<action type="update" dev="HLS">Make default binding prefix
configurable</action>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]