I don’t know your circumstances, but you might question why rank is a String in the first
place. Is the UI unduly influencing your data model? You could always add a synthetic
getter to your model itself and evade the eval altogether:
public int getRankInt() { … }
That’s an ugly hack, but if your rank attribute is really an integer anyway…
In any case, I’d suggest that you add a guard in your conversion utility to check for “”
and null Strings maybe default to 0 or throw some exception.
Cheers,
-Jess
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On
Behalf Of M.DILIP KUMAR
Sent: Tuesday, December 02, 2008 5:40 AM
To: Rules Users List
Subject: Re: [rules-users] Inline eval problem!
Hi ,
i can suggest one more way to solve it. Dont create instance in when part.
Instead of better you convert that helper class method as static methods.
So that u can call that method directly . but before that u should import that helper
class in drl file.
Or second way u can directly write a method in ur drl file itself.
Example :
import com.g2x.agility.leads.workflow.rulesengine.RuleUtilities;
rule"ConvertRule"
when
eval ( RuleUtilities.getStringToInteger( age) > 40)
// getStringToInteger(String age) is static method
then
System.out.print("XXXXName");
end
Defeat yourself today!
____________________________
DILIP KUMAR.M
--- On Tue, 2/12/08, vanshi <nilu.thakur(a)gmail.com> wrote:
From: vanshi <nilu.thakur(a)gmail.com>
Subject: [rules-users] Inline eval problem!
To: rules-users(a)lists.jboss.org
Date: Tuesday, 2 December, 2008, 10:38 AM
I need to convert a variable from string to intger in the rule. That variable
here is rank, so, I create a helper class called 'Conversion' with just
one
function/method, which is supposed to convert the string argument passed to
it, to an integer and then I call that method in rule as inline eval.
What's
wrong here because this is not working and I don't want to change
'When'
part too much because it has 10 or so other variable with &&
connective,
which I've removed for clarity here. Any input would be appreciated much.
package harules;
import com.hibernate.Person;
import com.uhg.utils.Conversion;
rule "one"
salience 10
when
$con: Conversion();
pers: Person(age!= null , age >= 18 , eval($con.getInteger(rank) > 140))
then
System.out.println("Evaluated true");
end
//content of Conversion class
package com.utils;
public class Conversion {
public Integer getInteger(String s)
{
return Integer.parseInt(s);
}
}
--
View this message in context:
http://www.nabble.com/Inline-eval-problem%21-tp20786253p20786253.html
Sent from the drools - user mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
________________________________
Add more friends to your messenger and enjoy! Invite them now.
<
http://in.rd.yahoo.com/tagline_messenger_6/*http:/messenger.yahoo.com/inv...