Hi

Generally, I'd treat null as "no-value". In all cases where there is
really no value or null, use the default supplied when calling
getValue[s]
If there is a value set in the portlet.xml -- then this is a real
value and pluto should not return the default value but the value from
the portlet.xml (or any previously stored value).
Calling setValue with null as value argument, should actually delete
the value, so the next getValue will return the default value, IIRC.

Answers to the specific questions are below, according to the text above.

Did you look at the spec, PLT.14?

Patrick

2006/2/17, Zhong ZHENG <[EMAIL PROTECTED]>:
> Hi,
>
>  I got some questions about the portlet preferences...
>
>  The following two methods should return the provided default value
>  if no value is bound to the given preference key:
>
>  PortletPreferences#getValue(String key, String def)
>  PortletPreferences#getValues(String key, String[] def)
>
>  While the following two methods set value (null is allowed!!) of a
> preference:
>
>  PortletPreferences#setValue(String key, String value)
>  PortletPreferences#setValues(String key, String[] values)
>
>  Here come the questions......
>
>  1/ If in portlet.xml we have:
>
>        <preference>
>          <name>toto</name>
>        </preference>
>
>  What should be returned if we call PortletPreferences.getValue("toto",
> "hello")?
>  We should get a null or "hello"?

"hello" -- the default value

>  What should be returned if we call PortletPreferences.getValues("toto", new
> String[] { "hello" })?
>  We should get an empty string array (length == 0)? or the default array?

the default array
>
>  2/ Take a look at the following code:
>
>  PortletPreferences prefs = ... // get preferences object
>  prefs.setValue("titi", null); // null is allowed!
>  String value = prefs.getValue("titi", "hello");
>  System.out.println(value);
>
>  What should we have on the console? null? hello?

"hello"

>
>  3/ code below:
>
>  PortletPreferences prefs = ... // get preferences object
>  prefs.setValues("titi", new String[] { null, "world" } );
>  String value = prefs.getValue("titi", "hello");
>  System.out.println(value);

"hello"

>
>  What should we have on the console? null? hello?
>
>  4/ code below:
>
>  PortletPreferences prefs = ... // get preferences object
>  prefs.setValues("titi", new String[0]);
>  String value = prefs.getValues("titi", new String[] { "hello" });
>  System.out.println(value.length);
>
>  What should we have on the console? 0? 1?

0

>
>  5/ code below:
>
>  PortletPreferences prefs = ... // get preferences object
>  prefs.setValues("titi", null);
>  String value = prefs.getValues("titi", new String[] { "hello" });
>  System.out.println(value);
>
>  What should we have on the console? null? the default array .toString()?

the array

>
>  Sorry for so many questions... But i am really quite confused about that...
>  I checked the portlet spec as well as the portlet API javadoc, but neither
>  has explained my questions clearly.
>
>  Thanks in advance!
>
>  Regards.
> --
> ZHENG Zhong
>  - http://heavyz.blogspot.com/
>  - http://people.apache.org/~zheng/
>


--
"I love deadlines. I like the whooshing sound they make as they fly
by." -- Douglas Adams

Reply via email to