In an application I need to know if a viewScope variable has been initialized. When the viewScope variable is created the value might be null. So viewScope.isEmpty("SomeName") does not tell me that it has been intialized and the answer is null or it has not been initialized yet. None of the viewScope properties seem to answer the question "dose the viewScope exist".
Asked
Active
Viewed 1,491 times
4
-
You can't set null as value of scope variable. If you do so, it is removed (according to my tests with SSJS/binding). It is counter intuitive compared to Java map. – Frantisek Kossuth Dec 10 '13 at 19:08
-
You can do viewScope.put("SomeName","") and the viewScope variable will be null. – Bill F Dec 11 '13 at 15:52
1 Answers
14
You can get the information whether a viewScope variable does exist or not with
if (viewScope.containsKey("SomeName")) ...

Knut Herrmann
- 30,880
- 4
- 31
- 67