Display contract failed constraints

1
0
-1

When a user submit a form with complex contract constraints and one of those contraint is not valid, we get a org.bonitasoft.engine.bpm.contract.ContractViolationException

The message associated with this exception is Exception while validating constraints and we also get an empty explanations array.

Is there a way to get the list of failed contraints? Also I believe the error message used to contain the error message associated with the failed constraint but my last tests (Bonita Community 7.3.3 and 7.2.3) does not show them.

Knowing the failed constraint is mandatory for complex form validation and good user experience.

2 answers

1
-1
-1
This one is the BEST answer!

Have a look at this HowTo for forms validation and display on the UI.
http://documentation.bonitasoft.com/?page=manage-control-in-forms

Works for us.

regards
Seán

PS: As this reply answers your question, please mark as resolved by ticking the tick mark on the left of this reply.

Comments

Submitted by g.lapierre on Mon, 02/27/2017 - 10:22

This would work if the explanations array was not empty (referencing "Use contract response for server side validation" chapter)

{ "exception": "class org.bonitasoft.engine.bpm.contract.ContractViolationException", "message": "Exception while validating constraints", "explanations": [] } 

I will have to test on a 7.4

Submitted by g.lapierre on Mon, 02/27/2017 - 10:32

On 7.4.2 explanations array is still empty. Is this a limitation of the community edition?

Submitted by g.lapierre on Thu, 03/16/2017 - 16:48

After digging in community source code, if message is "Exception while validating constraints" it means you have an exception thrown by the constraint groovy code, not that the constraint return false.

After some debugging in the constraints code I get an explanation array which can be used to display appropriate error messages to the user. There is no limitation in the community edition on this subject.

Submitted by Sean McP on Thu, 03/16/2017 - 18:53

That is excellent research @g. And well worth documenting for the future.

Many thanks

1
0
-1

If you add a var, type string at UI Designer, for example: error, and drop a text-widget:

HIDE: error == null and TEXT: Error : {{error.explanations | json}} , then, only the text for "explanation" at the CONSTRAINTS (Bonita Studio) , will be displayed, and the text:

"exception": "class org.bonitasoft.engine.bpm.contract.ContractViolationException", "message", will not displayed. 
Notifications