What is the result of an action? It is everything which the resulting JSP may use to render the output. This consists of:
The current implementation of StrutsME only includes the first option and a part of the second option: the form data and the messages are returned.
Because of the Struts forward mechanism it is possible that multiple actions are executed before a user-visible output is generated. In such a case only the form of the last execution is returned. To help the client to understand the returned data StrutsME will also send back the name of the last action. If the validation of a form fails, the initiated action is send back.
In case of an exception a string is sent back. In case of an org.strutsme.server.BusinessException the message from the exception will be taken unchanged. Otherwise a generic error message will be used.
As mentioned before requires the serialization employed in StrutsME
the help of the object which is serialized. This means that such classes have to extend
org.strutsme.common.serialization.SerializationBase
and implement the two abstract methods. The implementation may look like:
private static final UserDto extends SerializationBase {
USER_DTO_VERSION_ID = "0.0.1";
/**
* {@inheritDoc}
*/
public void copyValuesToBean(final SafeHashtable map)
throws SerializationException {
super.copyValuesToBean(map);
this.username = (String) map.get("username");
this.password = (String) map.get("password");
this.firstName = (String) map.get("firstName");
this.familyName = (String) map.get("familyName");
this.email = (String) map.get("email");
this.phone = (String) map.get("phone");
}
/**
* {@inheritDoc}
*/
public void copyValuesToMap(final SafeHashtable map)
throws SerializationException {
super.copyValuesToMap(map);
map.put(Constants.VERSION, USER_DTO_VERSION_ID);
map.put("username", this.username);
map.put("password", this.password);
map.put("firstName", this.firstName);
map.put("familyName", this.familyName);
map.put("email", this.email);
map.put("phone", this.phone);
}
}
Objects which implement org.strutsme.common.serialization.SerializationBase and have no other functionally are called data transfer objects (DTO). Only such DTOs are supported for the communication between client and server.
One of the goals of StrutsME
is that the existing Struts application is minimally changed. As such it would be problematic to change the superclass of existing classes to
org.strutsme.common.serialization.SerializationBase
. To avoid this a SerializationMapper
is introduced in StrutsME-Server
. It allows to substitute an object of an existing class with a new object of the corresponding DTO class. The object would than contain the same data but the data is now in form which is supported by the serialization. For this DTOs have to be written and placed in a common area which is available to both the client and the server.
The SerializationMapper searches for substitutes of classes, which could not be serialized, in a special package of this common area. The name of the package can be configured in the web.xml . The SerializationMapper identifies the correct substitute by the simple name of the class.
A example. The class to serialize is org.strutsme.wishlist.server.dto.UserDto . Since org.strutsme.wishlist.server.dto.UserDto doensn't derive from SerializationBase , the SerializerMapper searches for UserDto in the specified package of the common module. If found, the substituted class is instantiated and then populated with the values of original object. After that, the class is serialized. If the class could not be found, a exception is thrown.
Figure 1shows the flow of how an incoming request is processed on the server. On the left side the flow of a classic client is shown, while on the right side the flow of a StrutsME-Client is displayed. The HTTP attribute "Is-StrutsME-Request" is used by the RequestProcessor to detect the StrutsME-Client .