5. Data transfer: OGNL and type conversion Flashcards
What does OGNL stand for?
Object Graph Navigation Language
What’s the OGNL escape sequence?
%{expression}
What’s the difference between these fields when OGNL converts them to Java?
- ages – Sets the whole array.
- names – Sets individual index with value (calls get, then sets value). SO array MUST be initialized!
How do we tell OGNL what types to convert values to?
Create a ClassName-conversion.properties file next to the Java Class.
Regarding OGNL convertions properties file, how would you convert values named ‘weights’ from a generic list to a list of Doubles?
Add a line:
Element-weights=java.lang.Double
Note: Prefix of ‘Element-‘ and the full path to the Type.
What’s the syntax for using OGNL to populate a map from HTML?
Two ways you can do it:
map.key
or
map[‘key’]
Regarding HTML -> Java OGNL is the -conversion.properties NEEDED when dealing with List/Set/Map?
If you’re not using a typed generic, yet. But you should be using generics in which case it will work wihtout the properties file!
Ex: Map
What interface must be implemented to give OGNL ability to convert types? What 2 methods need to be implemented?
–Interface–
StrutsTypeConverter
–Methods–
convertFromString(Map context, String[] values, Class toClass)
String convertToString(Map context, Object o)
What is the OGNL properties file that’s used globally? Where should it be located?
xwork-conversion.properties
Place it in the root of the classpath.