24.7. Working with Data types
24.7.1. Primitives / Basic Types
This section describes the support for basic data types. On the server side, these values are generally compatible with either their primitive type, or their corresponding wrapper class.
24.7.1.1. String
Use JavaScript String objects to set String parameter values.
24.7.1.2. Number
Seam supports all Java-supported number types. On the client side, number values are always serialized as their String representation. They are converted to the correct destination type on the server side. Conversion into either a primitive or wrapper type is supported for
Byte, Double, Float, Integer, Long and Short types.
24.7.1.3. Boolean
Booleans are represented client-side by JavaScript Boolean values, and server-side by a Java Boolean.
24.7.2. JavaBeans
In general, these are either Seam entity or JavaBean components, or some other non-component class. Use the appropriate method to create a new instance of the object —
Seam.Component.newInstance() for Seam components, or Seam.Remoting.createType() for anything else.
Only objects created by either of these two methods should be used as parameter values, where the parameter is not one of the preexisting valid types. You may encounter component methods where the exact parameter type cannot be determined, such as:
@Name("myAction")
public class MyAction implements MyActionLocal {
public void doSomethingWithObject(Object obj) {
// code
}
}
In this case, the interface for
myAction will not include myWidget, because it is not directly referenced by any of its methods. Therefore, you cannot pass in an instance of your myWidget component unless you import it explicitly:
<s:remote include="myAction,myWidget"/>
This allows a
myWidget object to be created with Seam.Component.newInstance("myWidget"), which can then be passed to myAction.doSomethingWithObject().
24.7.3. Dates and Times
Date values are serialized into a String representation that is accurate to the millisecond. On the client side, use a JavaScript Date object to work with date values. On the server side, use any
java.util.Date class (or a descendant class, such as java.sql.Date or java.sql.Timestamp.)
24.7.4. Enums
On the client side, enums are treated similarly to Strings. When setting the value for an enum parameter, use the String representation of the enum. Take the following component as an example:
@Name("paintAction")
public class paintAction implements paintLocal {
public enum Color {red, green, blue, yellow, orange, purple};
public void paint(Color color) {
// code
}
}
To call the
paint() method with the color red, pass the parameter value as a String literal:
Seam.Component.getInstance("paintAction").paint("red");
The inverse is also true. That is, if a component method returns an enum parameter (or contains an enum field anywhere in the returned object graph), then on the client-side it will be represented as a String.
24.7.5. Collections
24.7.5.1. Bags
Bags cover all collection types, including arrays, collections, lists, and sets, but excluding maps — see the section following. They are implemented client-side as a JavaScript array, both when called and returned. The remoting framework on the server side can convert the bag to an appropriate type for the component method call.
24.7.5.2. Maps
The Seam Remoting framework provides simple map support where no native support is available in JavaScript. To create a map that can be used as a parameter to a remote call, create a new
Seam.Remoting.Map object:
var map = new Seam.Remoting.Map();
This JavaScript implementation provides basic methods for working with Maps:
size(), isEmpty(), keySet(), values(), get(key), put(key, value), remove(key) and contains(key). Each of these methods is equivalent to the Java method of the same name. Where the method returns a collection, as in keySet() and values(), a JavaScript array object will be returned that contains the key or value objects (respectively).