grailsmodel-view-controllergroovyclient-serveropendolphin

Why and how respond to OpenDolphin 'ValueChanged' confirmation


I have simple grails server/groovyfx app, where openDolphin is used for client/server communication.

Here is what happening: When CMD_LOG command is sended from client to server, server updates one value of presentationModel and responds: Whats up?. OpenDolphin does one more action, client send 'ValueChanged' confirmation, server acepts it, and responds empty command, and client receives it.

My question is, HOW can I implement custom respond to 'ValueChanged', for example check corresponding value in DB, or if client is allowed to change it. And WHY is respond sended, when I did not implement it? I dont feel well about sending empty messages out of my control.

Little bit of code, on client side, this closure is called on button press:

def sendToServer = { message ->
    clientDolphin.send(message, new OnFinishedHandlerAdapter() {
        @Override
        public void onFinished(List<ClientPresentationModel> presentationModels) {
            // after action on server, this wants to read changed presentation model
            }
        }
    });
}

client log:

INFO: C: sending batch of size 1
IX 17, 2013 7:46:59 ODP. java_util_logging_Logger$info$0 call
INFO: C:           -> Command: CMD_LOG
IX 17, 2013 7:46:59 ODP. org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrap invoke
INFO: C: server responded with 2 command(s): [ValueChanged, Whats up?]
IX 17, 2013 7:46:59 ODP. org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrap invoke
INFO: C: updating 'x' id '0' from 'null' to '10'
IX 17, 2013 7:46:59 ODP. java_util_logging_Logger$info$0 call
INFO: C: sending batch of size 1
IX 17, 2013 7:46:59 ODP. java_util_logging_Logger$info$0 call
INFO: C:           -> Command: ValueChanged attr:0, null -> 10
IX 17, 2013 7:46:59 ODP. org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrap invoke
SEVERE: C: cannot handle unknown command 'Command: Whats up?'
IX 17, 2013 7:47:00 ODP. org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrap invoke
INFO: C: server responded with 0 command(s): []

Server side, corresponding action handler:

class SimpleStoreServerDirector extends DolphinServerAction {
    @Override
    void registerIn(ActionRegistry actionRegistry) {

        actionRegistry.register "CMD_LOG", { NamedCommand command, response ->
            def pm = serverDolphin.findPresentationModelById("input")
            changeValue pm["x"], 10

            response.add(new NamedCommand("Whats up?"))
        }
}

And finally, server log:

Creating new Dolphin session
LOG: proccessing Command: CreatePresentationModel pmId input pmType null  attributes [[id:0, propertyName:x, tag:VALUE, value:null, qualifier:null]]
LOG results: []
LOG: proccessing Command: CMD_LOG
LOG results: [Command: ValueChanged attr:0, null -> 10, Command: Whats up?]
LOG: proccessing Command: ValueChanged attr:0, null -> 10
LOG results: []

Thaks in advace for answers, or any useful doc or tutorials references.


Solution

  • Q: HOW can I implement custom respond to 'ValueChanged' A: Just like with any other command you can register a handler for the ValueChanged Command. See shared tacho demo for an example.

    Q: Why is an empty response sended? A: That is the behaviour of the StoreValueChangeAction, which is one of the default actions. It stores the value change in the model store and since every request must return something it returns the empty command list.