Dynamically create ValidationFeedback action

I have the following situation: an entity with 10 fields with different names: FIELD1, FIELD2, FIELD3, etc. Now all 10 fields have the same data validation logic. And they should also show the same error. So what I want to create is a Java Action to which I can just pass the name of the field. That Java Action will get the proper field dynamically and validate it. If the validation fails I do want to show a validation message for that field. This means I need to be able to create the Validation Feedback action dynamically. Can this be achieved? Currently I have to write the validation logic and error message 10 times, which makes maintenance quite hard. I'm guessing I have to use the context.addFeedback option. But I cannot seem to find an example on how to create a proper IFeedback object and initialize it properly.
1 answers

I haven't tried this but this might work:


DataValidationInfo dvi = new DataValidationInfo(SomeObject.getMendixObject().getId().toLong());
dvi.addErrorField(SomeProxyObject.MemberNames.Email.toString(), "some validation message");


SomeObject.getMendixObject().getId().toLong() = the guid of the object the attribute belongs to

SomeProxyObject.MemberNames.Email.toString() = the membername, so the name of the attribute or association where you would like to show a validation message.



context.addFeedback is used to sent generic feedback to the client to open/close a page, show a popup etc.