It seems that patterns that worked for classic UI won’t work for FlowUI.
First, try getting the task not in the handler of the InitEvent, but in the handler of BeforeShow event.
Second, I’m not sure that StandardDetailView
works correctly as a process form. Try to inherit your form not from the StandardDetailView
, but from the StandardView
.
The code below worked for me:
@ProcessForm
@Route(value = "order-process-form", layout = MainView.class)
@ViewController("OrderProcessForm")
@ViewDescriptor("order-process-form.xml")
@EditedEntityContainer("orderDc")
public class OrderProcessForm extends StandardView {
private static final Logger log = LoggerFactory.getLogger(OrderProcessForm.class);
@Autowired
private ProcessFormContext processFormContext;
@ProcessVariable
private Order order;
@ViewComponent
private InstanceContainer<Order> orderDc;
@ViewComponent
private DataContext dataContext;
@Subscribe
public void onBeforeShow(final BeforeShowEvent event) {
Task task = processFormContext.getTask();
log.info("Task in beforeShow: {}", task);
//Merge process variable into dataContext.
//After that changes in UI components related with orderDc will be tracked
Order managedOrder = dataContext.merge(order);
//set merged entity into data container
orderDc.setItem(managedOrder);
}
@Subscribe("completeTaskBtn")
public void onCompleteTaskBtnClick(final ClickEvent<JmixButton> event) {
//save dataContext - changes in the edited order entity will be saved to the database
dataContext.save();
//complete the user task
processFormContext.taskCompletion().complete();
closeWithDefaultAction();
}
@Subscribe("closeBtn")
public void onCloseBtnClick(final ClickEvent<JmixButton> event) {
close(StandardOutcome.CLOSE);
}
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<view xmlns="http://jmix.io/schema/flowui/view"
title="msg://orderProcessForm.title"
focusComponent="form">
<data>
<instance id="orderDc"
class="com.company.bpmprocesstask.entity.Order">
<fetchPlan extends="_base"/>
<loader/>
</instance>
</data>
<facets>
<dataLoadCoordinator auto="true"/>
</facets>
<layout>
<formLayout id="form" dataContainer="orderDc">
<textField id="numberField" property="number"/>
<datePicker id="dateField" property="date"/>
</formLayout>
<hbox id="detailActions">
<button id="completeTaskBtn" text="Complete task"/>
<button id="closeBtn" text="Close"/>
</hbox>
</layout>
</view>