Search code examples
javaisiscommand-execution

CommandExecuteIn Background throws a "Not an (encodable) value" error


I am currently trying to implement file exports in background so that the user can do some actions while the file is downloading.

I used the apache isis CommandExexuteIn:Background action attribute. However, I got an error "Not an (encodable) value", this is an error thrown by the ScalarValueRenderer class.

This is how my method looks like:

@Action(semantics = SemanticsOf.SAFE,
        command = CommandReification.ENABLED)
        commandExecuteIn =  CommandExecuteIn.BACKGROUND)
public Blob exportViewAsPdf() {
    final Contact contact = this;
    final String filename = this.businessName + " Contact Details";

    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("contact", contact);

    final String template = templateLoader.buildFromTemplate(Contact.class, "ContactViewTemplate", parameters);
    return pdfExporter.exportAsPdf(filename, template);
}

I think the error has something to do with the command not actually invoking the action but returns the persisted background command.

This implementation actually worked on the method where there is no return type. Did I miss something? Or is there a way to implement background command and get the expected results?


Solution

  • interesting use case, but it's not one I anticipated when that part of the framework was implemented, so I'm not surprised it doesn't work. Obviously the error message you are getting here is pretty obscure, so I've raised a JIRA ticket to see if we could at least improve that.

    I'm interested to know in what user experience you think the framework should provide here?

    In the Estatio application that we work on (that has driven out many of the features added to the framework over the last few years) we have a somewhat similar requirement to obtain PDFs from a reporting server (which takes 5 to 10 seconds) and then download them. This is for all the tenants in a shopping centre, so there could be 5 to 50 of these to generate in a single go. The design we went with was to move the rendering into a background command (similar to the templateLoader.buildFromTemplate(...) and pdfExporter.exportAsPdf(...) method calls in your code fragment, and to capture the output as a Document, via the document module. We then use the pdfbox addon to stitch all the document PDFs together as a single downloadable PDF for printing.

    Hopefully that gives you some ideas of a different way to support your use case

    Thx Dan