Assuming you have<br><br> class ApplicationData{ String age; int intAge;... }<br><br>you might do<br> rule one<br> when<br> ad : ApplicationData( $age: age != null && != "" && matches "\\d+" )<br>
then<br> modify( ad ){ setIntAge( Integer.parseInt($age) ) }<br> end<br> rule two<br>
when<br> ad : ApplicationData( intAge < 0 )<br> then<br> ...error...<br> end<br><br>Or, anoither possibilitie:<br> when<br> ad : ApplicationData( $age: age != null && != "" && matches "\\d+" )<br>
eval( Integer.parseInt($age) < 0 )<br> then<br> ...error...<br> end<br><br>-W<br><div class="gmail_quote">On 25 March 2011 18:46, Benson Fung <span dir="ltr"><<a href="mailto:benson.redhat@gmail.com">benson.redhat@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">so how can I change it to integer in the rule?<br>
<br>
<br>
<br>
2011/3/26 Wolfgang Laun <<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>>:<br>
> If it's stored in a fact field of type int: yes.<br>
><br>
> The way you write it: no.<br>
><br>
> -W<br>
><br>
><br>
> On 25 March 2011 18:37, Benson Fung <<a href="mailto:benson.redhat@gmail.com">benson.redhat@gmail.com</a>> wrote:<br>
>><br>
>> If the age is String type, can I use Integer.parseInt(age) to change<br>
>> to integer and then evaluate it?<br>
>><br>
>> like<br>
>><br>
>> when<br>
>> ad : ApplicationData(Integer.parseInt(age) < 0)<br>
>> then<br>
>> ad.setReturnMsg("age should not be negative 0")<br>
>> end<br>
>><br>
>><br>
>><br>
>><br>
>> 2011/3/26 Wolfgang Laun <<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>>:<br>
>> > Sorry, I don't use guided editors.<br>
>> > -W<br>
>> ><br>
>> > On 25 March 2011 18:17, Benson Fung <<a href="mailto:benson.redhat@gmail.com">benson.redhat@gmail.com</a>> wrote:<br>
>> >><br>
>> >> Hi Wolfgang,<br>
>> >><br>
>> >> I managed to author this rule(ApplicationData( age == null || age ==<br>
>> >> "" )) via Technical Rules editor of BRMS.<br>
>> >> However, I cannot create this rule via Business Rule Guided Editor of<br>
>> >> BRMS.<br>
>> >><br>
>> >> Could you let me know how?<br>
>> >><br>
>> >><br>
>> >> Thanks<br>
>> >><br>
>> >><br>
>> >><br>
>> >> 2011/3/26 Wolfgang Laun <<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>>:<br>
>> >> > You can't use a method call as the left hand side operand in a<br>
>> >> > constraint;<br>
>> >> > thus<br>
>> >> > age.size() == 0<br>
>> >> > is not correct.<br>
>> >> ><br>
>> >> > Do you really mean<br>
>> >> > age == "null"<br>
>> >> ><br>
>> >> > Probably<br>
>> >> > ApplicationData( age == null || age == "" )<br>
>> >> > is the right thing to do, provided that ApplicationData.age is a<br>
>> >> > String.<br>
>> >> ><br>
>> >> > -W<br>
>> >> ><br>
>> >> > On 25 March 2011 17:32, Benson Fung <<a href="mailto:benson.redhat@gmail.com">benson.redhat@gmail.com</a>> wrote:<br>
>> >> >><br>
>> >> >> Hi,<br>
>> >> >><br>
>> >> >> I got the following rule problem.<br>
>> >> >><br>
>> >> >> The rule is like :<br>
>> >> >><br>
>> >> >> 1. | rule "Rule1"<br>
>> >> >> 2. | dialect "mvel"<br>
>> >> >> 3. | when<br>
>> >> >> 4. | ad : ApplicationData( age == "null" ,<br>
>> >> >> age.size()<br>
>> >> >> == 0)<br>
>> >> >> 5. | then<br>
>> >> >> 6. | ad.setReturnMsg( "age should not be null or<br>
>> >> >> empty"<br>
>> >> >> );<br>
>> >> >> 7. | end<br>
>> >> >><br>
>> >> >> where setReturnMsg is a method of ApplicationData Fact();<br>
>> >> >><br>
>> >> >> However, I got the validation error :<br>
>> >> >><br>
>> >> >> [Rule1] [ERR 101] Line 4:49 no viable alternative at input ')' in<br>
>> >> >> rule<br>
>> >> >> "Rule1" in pattern ApplicationData<br>
>> >> >> [Rule1] [ERR 102] Line 4:51 mismatched input '==' expecting ')' in<br>
>> >> >> rule "Rule1" in pattern ApplicationData<br>
>> >> >><br>
>> >> >> Please help what the problem is.<br>
>> >> >><br>
>> >> >><br>
>> >> >> Thanks<br>
>> >> >> _______________________________________________<br>
>> >> >> rules-users mailing list<br>
>> >> >> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
>> >> >> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
>> >> ><br>
>> >> ><br>
>> >> > _______________________________________________<br>
>> >> > rules-users mailing list<br>
>> >> > <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
>> >> > <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
>> >> ><br>
>> >> ><br>
>> >><br>
>> >> _______________________________________________<br>
>> >> rules-users mailing list<br>
>> >> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
>> >> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
>> ><br>
>> ><br>
>> > _______________________________________________<br>
>> > rules-users mailing list<br>
>> > <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
>> > <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
>> ><br>
>> ><br>
>><br>
>> _______________________________________________<br>
>> rules-users mailing list<br>
>> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
>> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
><br>
><br>
> _______________________________________________<br>
> rules-users mailing list<br>
> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
><br>
><br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br>