[rules-users] Getting validation errors

Marcus Ilgner marcus.ilgner at gmail.com
Tue Mar 13 07:26:36 EDT 2007


Hi Mike,

On 3/13/07, Mike Dougherty <mjdougherty at gmail.com> wrote:
> Hello,
>
> I am using JBoss Rules to validate entities before storing them in the
> database. I therefore need a way to inform the calling code that the entity
> which was asserted failed verification. The only way I have been able to
> find that works is to assert an exception from within the rule file. For
> example:
>
> rule "user is 'miked'"
>   when
>     identity : Identity( username == "miked" )
>   then
>     assertLogical(new IllegalStateException("Entity failed verification."));
> end
>
> Then in the Java that fires the rule, I have:
>
> workingMemory.fireAllRules();
> for(Iterator i = workingMemory.getObjects(Exception.class).iterator();
> i.hasNext(); ) {
>     System.out.println("Exception: "+i.next());
> }
>
> Which seems to be working OK. But I wanted to see if maybe there is a better
> way to accomplish what I need.
>
> Thanks for you help.
> Mike
>

My approach would be to derive all objects that will be validated from
a superclass, e.g. ValidatedObject, which provides a boolean property
"validated".
Then you can set this property in your rules and later on display
warning/error messages for those objects that failed validation.

Best regards
Marcus



More information about the rules-users mailing list