Page 1 of 1

Concept for custom java interaction

Posted: Thu Nov 26, 2020 4:57 pm
by Patrik
Hi,

I'm using quite some custom implementations of AuthorOperationWithResult to be called by the ActionsManager form the js code.

The documentation of ActionsManager.invokeOperation() claims that on an exception the user will see an error message. Actually this doesn't happen for me. I find the exception i nthe server log but on the client side I get error and result both as null.

So how do I more complex results to the client without parsing a string? For instance a list of objects (in my case a list of key-value-pairs) or an error message?

Thanks and regards,
Patrik

Re: Concept for custom java interaction

Posted: Thu Nov 26, 2020 8:44 pm
by cristi_talau
The documentation is a bit misleading the exception has to be an instance of "AuthorOpertionException" and its "isOperationRejectedOnPurpose" should return true to be displayed on the client.

Unfortunately, only strings can be passed to the client-side code. Then, as you thought you have to parse it to extract the status of the operation.

Re: Concept for custom java interaction

Posted: Fri Nov 27, 2020 2:29 pm
by Patrik
Hi,

thanks. I've created my own class AuthorOperationOnPurposeException with setOperationRejectedOnPurpose(true) in the constructor and it behaves as expected.

In case anybody else has a similiar problem: I also found a comfortable way to pass my key-value-map to my JS code:
Java:

Code: Select all

import org.codehaus.jackson.map.ObjectMapper;
[...]
final String result= new ObjectMapper().writeValueAsString(map.entrySet().toArray());
JS code:

Code: Select all

[...]
var list = JSON.parse(result);
var length = list.length;
for (var i = 0; i < length; ++i) {
    	var entry = list[i];
        [...]
 }
Regards,
Patrik