Camunda用户任务嵌入HTML表单报错:值'on'非布尔类型求助
Hey there, let's work through this Camunda form issue you're hitting—it's a super common gotcha with HTML forms in Camunda!
What's Causing This?
This error almost always stems from a checkbox (or toggle-style control) in your HTML form being bound to a Camunda variable defined as a Boolean type. By default, when you check a standard HTML checkbox, the browser sends the string value 'on' instead of a proper boolean true/false. Camunda throws an error because it expects a boolean but receives a mismatched string type.
How to Fix It
Here are two straightforward solutions to resolve this:
1. Use Camunda's Form Directives to Map Boolean Values
Camunda has built-in directives to handle boolean form controls correctly. Add these attributes to your checkbox input to ensure it sends valid boolean values to Camunda:
<input type="checkbox" cam-variable-name="yourBooleanVariable" cam-variable-type="Boolean" cam-true-value="true" cam-false-value="false" id="approvalCheckbox">
cam-variable-type="Boolean"explicitly tells Camunda to treat this variable as a boolean type.cam-true-valueandcam-false-valuemap the checkbox's checked/unchecked state to valid boolean values Camunda understands.
2. Convert the Value via a Task Submit Listener
If you can't modify the form directly (or prefer handling the conversion server-side), add a submit listener to your user task in Camunda Modeler:
- Open your user task's properties panel.
- Navigate to the Listeners tab, add a new listener with the event type
submit. - Select Script as the listener type, pick Groovy (or your preferred scripting language), and add this code:
def variableValue = execution.getVariable("problemVariableName") // Replace "problemVariableName" with the actual variable triggering the error if (variableValue == "on") { execution.setVariable("problemVariableName", true) } else { execution.setVariable("problemVariableName", false) }
Quick Check for Your Code
Looking at your truncated form snippet, the <a> download link shouldn't be the culprit here. Double-check any other form elements (like hidden inputs or checkboxes) that might be linked to a boolean variable in your process—this is where the mismatched type is likely coming from.
内容的提问来源于stack exchange,提问作者CodingGirl

