Listener for form submit

Question: is there a listener/hook for form submission?

Have a requirement to investigate, which is played out against the idea of submitting a form, validating its content (and fields), after which wrap those fields under a specific parent object.

Hello @Draakzward ,

this is possible in the backend and frontend:

In the backend, you can register a task listener on complete of a user task.

In the frontend, you can use embedded forms that have some lifecycle hooks.

I hope this helps

Jonathan

2 Likes

Thank you, seems to be what I am looking for

One newbie question to ask - how do I override the TaskServiceImpl?
The project is Spring Boot based, so I tried the first thing that came to my mind - @Component. But it does not get utilized. I put a few log.info’s for complete methods, which seem to be form submit actions, but I see none in the logs (I do see Constructor’s log working though).

I am trying the simplest MyClass extends TaskServiceImpl.

Hello @Draakzward ,

what are you trying to achieve?

The service is not meant to be extended…

Jonathan

I’m trying to either extend TaskService.complete method, or achieve what is actually done by that action.

The goal is to capture the “onSubmit” action when a User task form gets submitted, and before that data gets stored - do some server side validation (and final result transformation).

Meaning…

I have a form with 3 input fields. I typed some data to it and pressed “Submit”. Now, before that data gets stored, I want to alter it and maybe conduct some additional validation.

Hello @Draakzward ,

why would the backend task listener complete not suit this?

Jonathan

Hm.
I’m assuming that

with the DelegateTask not holding the form data, which will end up in submit. Unless I process the data after it gets persisted.

Or am I missing something?

In other words, I have a Camunda form on one side and a POST /task/{id}/submit-form on the other. Thing is - nothing is stopping me from submitting random data to that form, bypassing any validation defined in the form. Yes, FE should handle this, but BE validation was made for a special reason (mainly for those people, who not long ago discovered how to use YouTube as a file storage). So I want a reliable way (but, currently, without a custom SUBMIT endpoint), in which I would intercept the POST submit-form before it gets stored.

Thanks.

Found my solution with

@Bean
	public ProcessEngineConfigurationImpl processEngineConfiguration(List<ProcessEnginePlugin> processEnginePlugins) {
		
		System.out.println("***************************************");
		final SpringProcessEngineConfiguration configuration = CamundaSpringBootUtil.springProcessEngineConfiguration();
		configuration.getProcessEnginePlugins().add(new CompositeProcessEnginePlugin(processEnginePlugins));
		
		return configuration.setFormService(new FormServiceTheSecond());
		//return configuration;
	}

Hello @Draakzward ,

this solution will probably work, however there are more elegant (easier, better maintainable, less side-effect prone) ways to do it.

Instead of bootstrapping the process engine in a seperate way (which could have side-effects) and extending the form service, there are less invasive ways of using tasklisteners:

Your provided solution does not work as the task listener needs to be registered:

  1. to the process model: On a user task, select task listeners, then add one on complete. Provide either the class directly or the bean name.

  2. Programatically: For a more generic approach, create a process engine plugin that the adds a parse listener on user tasks, registering a task listener there.

Alternative: For a process-engine independent (pure data-handling) way, you can also register a filter to the submit form endpoint.

Jonathan

Hi,
I understand that my way is not elegant (and I would want a better solution by myself).

Programatically: For a more generic approach, create a process engine plugin that the adds a parse listener on user tasks, registering a task listener there.

Tried that as well. But the main problem here is that I’m inplementing a TaskListener, which gives me a DelegateTask, and a “event == complete”. If to call getVariables from there, I already see there data, submitted by the form, which is too late.

Alternative: For a process-engine independent (pure data-handling) way, you can also register a filter to the submit form endpoint.

Hm. Need to see what it is. Thanks

Your provided solution does not work as the task listener needs to be registered:

Yeah, I know that. However, this I found somewhere in the Camunda 7 documentation as a “up-to-date” solution.

@jonathan.lukas I’m having a bit of trouble finding the documentation for the you can also register a filter to the submit form endpoint.. May I ask you to point me to that piece?

Hello @Draakzward ,

Tried that as well. But the main problem here is that I’m inplementing a TaskListener, which gives me a DelegateTask , and a “event == complete”. If to call getVariables from there, I already see there data, submitted by the form, which is too late.

Given that the process engine works transactional, the variables available from are not yet submitted to the database, but part of the transaction. If you throw an exception at this point, the command will be rolled back, leaving no traces of variables.

Regarding the bean solution: This works if you actively register this bean as listener to the process model, using the bean name as delegate expression. The bean only will not help as it needs to be called.

The filter is a mechanism provided by the container (Tomcat/Spring Boot in most cases).

Jonathan

1 Like

Thanks, I was missing the understanding that the data wasn’t committed.

1 Like