Create a Presentation Model from the (client) viewThe client dolphin has a
presentationModelfactory method that instantiates a ClientPresentationModel and adds it to the client side ModelStore such that all required listeners are set up and the server is notified about the construction.
Java styleThe recommended way to create a presentation model in Java on the client side is by using the presentationModel factory method that sets
- the unique id (if null it will be set to a generated id)
- the type (may be null if no type is required)
- a variable argument list of ClientAttributes,
ClientPresentationModel pm = clientDolphin.presentationModel("myPmId", "myPmType", firstNameAtt, lastNameAtt);
Groovy styleIn Groovy you can do the exact same as in Java or use one of the following shortcuts.Generate attributes with null values from a list of attribute names.
Generate attributes from named arguments or a map.
def pm = clientDolphin.presentationModel("myPmId", ["firstName", "lastName"])
Using constants (recommended) for any variant of the above.
def pm = clientDolphin.presentationModel("myPmId", firstName:"Dierk", lastName:"Koenig")
final FIRST = "firstName" final LAST = "lastName" // mind the parentheses def pm = clientDolphin.presentationModel("myPmId", (FIRST):"Dierk", (LAST):"Koenig")
Create a Presentation Model from the (server) controllerOn the server side, the construction of a presentation model looks very similar but works quite differently behind the scenes. The reason is that on the server side, presentation models are not directly constructed but the the client is advised to do so. After the client has created the presentation model, the server is notified and the actual creation happens automatically as part of the general synchronization process.The server dolphin has a
presentationModelconvenience method that sends a CreatePresentationModelCommand to the client.Since server-side constructions of presentation models do not instantiate any presentation models themselves, there also are no attributes to create the models from. Instead, we use Data Transfer Objects (DTOs) and api:Slots.See also Guide:dto_purpose.The
presentationModelconvenience method needs to know the current response (list of commands) such that it can send the CreatePresentationModelCommand. Therefore, you will see the
responseas a parameter to the method.When inside a DolphinServerAction the current response is known and the method call is a bit shorter. We list both alternatives.
Java styleFrom anywhere:
From inside a DolphinServerAction:
getServerDolphin().presentationModel(response, "MyPmId", "MyType", new DTO( new Slot("firstName", "Dierk"), new Slot("lastName", "Koenig") );
presentationModel("MyPmId", "MyType", new DTO( new Slot("firstName", "Dierk"), new Slot("lastName", "Koenig") );
Groovy style or any other functional languageYou may want to create DTOs from a map. Otherwise the calls are identical
Map data = [firstName: "Dierk", lastName:"Koenig"] presentationModel "MyPmId", "MyType", new DTO(Slot.slots(data))
Create client-side-only Presentation ModelsOpenDolphin supports presentation models that are only created on the client (view) and synchronized back to the server (controller).
Client-side only presentation models remain fully functional on the client side, i.e. binding, updates, and handling of qualifiers is exactly the same.The typical use case is the collection of search result presentation models, which are often not needed on the server side.The api is exactly the same, only the method name changes to
They are just not visible on the server.
getServerDolphin().clientSideModel(response, "MyPmId", "MyType", new DTO( new Slot("firstName", "Dierk"), new Slot("lastName", "Koenig") );