Author: julien_viet
Date: 2010-03-03 05:40:53 -0500 (Wed, 03 Mar 2010)
New Revision: 1939
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/spi/portlet/PortletState.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/spi/portlet/Preference.java
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestPortletPreferences.java
Log:
GTNPORTAL-707 : Cannot save portlet preference with null value
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/spi/portlet/PortletState.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/spi/portlet/PortletState.java 2010-03-03
10:16:54 UTC (rev 1938)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/spi/portlet/PortletState.java 2010-03-03
10:40:53 UTC (rev 1939)
@@ -23,6 +23,8 @@
import org.gatein.mop.core.api.MOPFormatter;
import org.gatein.mop.core.api.workspace.content.AbstractCustomizationState;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
/**
@@ -45,19 +47,36 @@
public void setPayload(Portlet payload)
{
- this.payload = payload;
-
- //
Map<String, PreferenceState> entries = getChildren();
entries.clear();
for (Preference pref : payload)
{
PreferenceState prefState = create();
+
+ //
entries.put(pref.getName(), prefState);
- prefState.setValue(pref.getValues());
+
+ // Compute values
+ List<String> toCopyValues = pref.getValues();
+ ArrayList<String> copiedValues = new
ArrayList<String>(toCopyValues.size());
+ for (int i = 0;i < toCopyValues.size();i++)
+ {
+ String value = toCopyValues.get(i);
+ if (value == null)
+ {
+ value = "";
+ }
+ copiedValues.add(value);
+ }
+
+ //
+ prefState.setValue(copiedValues);
prefState.setReadOnly(pref.isReadOnly());
}
+
+ // Invalidate payload that will be reloaded next time
+ payload = null;
}
public Portlet getPayload()
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/spi/portlet/Preference.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/spi/portlet/Preference.java 2010-03-03
10:16:54 UTC (rev 1938)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/spi/portlet/Preference.java 2010-03-03
10:40:53 UTC (rev 1939)
@@ -56,13 +56,6 @@
{
throw new IllegalArgumentException();
}
- for (String value : values)
- {
- if (value == null)
- {
- throw new IllegalArgumentException();
- }
- }
//
this.name = name;
@@ -76,10 +69,6 @@
{
throw new NullPointerException();
}
- if (value == null)
- {
- throw new NullPointerException();
- }
//
this.name = name;
Modified:
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestPortletPreferences.java
===================================================================
---
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestPortletPreferences.java 2010-03-03
10:16:54 UTC (rev 1938)
+++
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestPortletPreferences.java 2010-03-03
10:40:53 UTC (rev 1939)
@@ -87,4 +87,23 @@
assertNotNull(prefs);
assertEquals(new PortletBuilder().add("template",
"someanothervalue").build(), prefs);
}
+
+ public void testNullPreferenceValue() throws Exception
+ {
+ Page page = storage_.getPage("portal::test::test4");
+ Application<Portlet> app =
(Application<Portlet>)page.getChildren().get(0);
+ PersistentApplicationState<Portlet> state =
(PersistentApplicationState)app.getState();
+
+ //
+ Portlet prefs = storage_.load(state, ApplicationType.PORTLET);
+
+ //
+ prefs.setValue("template", null);
+ storage_.save(state, prefs);
+
+ //
+ prefs = storage_.load(state, ApplicationType.PORTLET);
+ assertNotNull(prefs);
+ assertEquals(new PortletBuilder().add("template", "").build(),
prefs);
+ }
}