I'd assume you set "null" as a literal value on the rule?
There's sort of a problem, AFAIK, that all literals are escaped as String in
the RHS of a rule.
You might be best suited to electing to use "New Formula" and specifying the
text "age ==null || age.size() == 0".
This generates an inline eval for your constraint, which although not
optimal, should work.
With kind regards,
Mike
2011/3/25 Wolfgang Laun <wolfgang.laun(a)gmail.com>
Assuming you have
class ApplicationData{ String age; int intAge;... }
you might do
rule one
when
ad : ApplicationData( $age: age != null && != "" &&
matches "\\d+" )
then
modify( ad ){ setIntAge( Integer.parseInt($age) ) }
end
rule two
when
ad : ApplicationData( intAge < 0 )
then
...error...
end
Or, anoither possibilitie:
when
ad : ApplicationData( $age: age != null && != "" && matches
"\\d+" )
eval( Integer.parseInt($age) < 0 )
then
...error...
end
-W
On 25 March 2011 18:46, Benson Fung <benson.redhat(a)gmail.com> wrote:
> so how can I change it to integer in the rule?
>
>
>
> 2011/3/26 Wolfgang Laun <wolfgang.laun(a)gmail.com>:
> > If it's stored in a fact field of type int: yes.
> >
> > The way you write it: no.
> >
> > -W
> >
> >
> > On 25 March 2011 18:37, Benson Fung <benson.redhat(a)gmail.com> wrote:
> >>
> >> If the age is String type, can I use Integer.parseInt(age) to change
> >> to integer and then evaluate it?
> >>
> >> like
> >>
> >> when
> >> ad : ApplicationData(Integer.parseInt(age) < 0)
> >> then
> >> ad.setReturnMsg("age should not be negative 0")
> >> end
> >>
> >>
> >>
> >>
> >> 2011/3/26 Wolfgang Laun <wolfgang.laun(a)gmail.com>:
> >> > Sorry, I don't use guided editors.
> >> > -W
> >> >
> >> > On 25 March 2011 18:17, Benson Fung <benson.redhat(a)gmail.com>
wrote:
> >> >>
> >> >> Hi Wolfgang,
> >> >>
> >> >> I managed to author this rule(ApplicationData( age == null || age
==
> >> >> "" )) via Technical Rules editor of BRMS.
> >> >> However, I cannot create this rule via Business Rule Guided Editor
> of
> >> >> BRMS.
> >> >>
> >> >> Could you let me know how?
> >> >>
> >> >>
> >> >> Thanks
> >> >>
> >> >>
> >> >>
> >> >> 2011/3/26 Wolfgang Laun <wolfgang.laun(a)gmail.com>:
> >> >> > You can't use a method call as the left hand side operand
in a
> >> >> > constraint;
> >> >> > thus
> >> >> > age.size() == 0
> >> >> > is not correct.
> >> >> >
> >> >> > Do you really mean
> >> >> > age == "null"
> >> >> >
> >> >> > Probably
> >> >> > ApplicationData( age == null || age == "" )
> >> >> > is the right thing to do, provided that ApplicationData.age is
a
> >> >> > String.
> >> >> >
> >> >> > -W
> >> >> >
> >> >> > On 25 March 2011 17:32, Benson Fung
<benson.redhat(a)gmail.com>
> wrote:
> >> >> >>
> >> >> >> Hi,
> >> >> >>
> >> >> >> I got the following rule problem.
> >> >> >>
> >> >> >> The rule is like :
> >> >> >>
> >> >> >> 1. | rule "Rule1"
> >> >> >> 2. | dialect "mvel"
> >> >> >> 3. | when
> >> >> >> 4. | ad : ApplicationData( age ==
"null" ,
> >> >> >> age.size()
> >> >> >> == 0)
> >> >> >> 5. | then
> >> >> >> 6. | ad.setReturnMsg( "age should
not be null
> or
> >> >> >> empty"
> >> >> >> );
> >> >> >> 7. | end
> >> >> >>
> >> >> >> where setReturnMsg is a method of ApplicationData Fact();
> >> >> >>
> >> >> >> However, I got the validation error :
> >> >> >>
> >> >> >> [Rule1] [ERR 101] Line 4:49 no viable alternative at input
')' in
> >> >> >> rule
> >> >> >> "Rule1" in pattern ApplicationData
> >> >> >> [Rule1] [ERR 102] Line 4:51 mismatched input '=='
expecting ')'
> in
> >> >> >> rule "Rule1" in pattern ApplicationData
> >> >> >>
> >> >> >> Please help what the problem is.
> >> >> >>
> >> >> >>
> >> >> >> Thanks
> >> >> >> _______________________________________________
> >> >> >> rules-users mailing list
> >> >> >> rules-users(a)lists.jboss.org
> >> >> >>
https://lists.jboss.org/mailman/listinfo/rules-users
> >> >> >
> >> >> >
> >> >> > _______________________________________________
> >> >> > rules-users mailing list
> >> >> > rules-users(a)lists.jboss.org
> >> >> >
https://lists.jboss.org/mailman/listinfo/rules-users
> >> >> >
> >> >> >
> >> >>
> >> >> _______________________________________________
> >> >> rules-users mailing list
> >> >> rules-users(a)lists.jboss.org
> >> >>
https://lists.jboss.org/mailman/listinfo/rules-users
> >> >
> >> >
> >> > _______________________________________________
> >> > rules-users mailing list
> >> > rules-users(a)lists.jboss.org
> >> >
https://lists.jboss.org/mailman/listinfo/rules-users
> >> >
> >> >
> >>
> >> _______________________________________________
> >> rules-users mailing list
> >> rules-users(a)lists.jboss.org
> >>
https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users(a)lists.jboss.org
> >
https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users