[rules-users] Question / problem

FrankVhh frank.vanhoenshoven at agserv.eu
Thu May 12 05:59:32 EDT 2011


Hi,

On a sidenote, there is also no real need to use the eval statement.

rule "FirstRule"
     when
         $testDrools : TestDroolsDto(myValue != "")
     then
         System.out.println("Set my value to 1");
         $testDrools.setMyValue("1");
         update($testDrools);
end

rule "SecondRule"
     when
         $testDrools : TestDroolsDto(myValue == "")
     then
         System.out.println("My Value : " + $testDrools.getMyValue() );
end

As you are only calling your getter methods, you do not need to use the eval
statement in the second rule. 

In the first rule, your eval did not really do much, as the condition of the
rule was completely dependable on the presence of TestDrools. And, as the
others stated, to prevent you from getting in a loop after calling Update(),
you can add an extra constraint in the rule.

Regards,
Frank


ino.nicolas wrote:
> 
> Hi,
> 
> I've got a little question. I've got a drl file which contains two rules :
> 
> rule "FirstRule"
>      salience 99
>      when
>          $testDrools : TestDroolsDto()
>          eval ( 1 == 1 )
>      then
>          System.out.println("Set my value to 1");
>          $testDrools.setMyValue("1");
> 
> end
> 
> rule "SecondRule"
>      salience 1
>      when
>          $testDrools : TestDroolsDto()
>          eval( $testDrools.getMyValue().equals("") )
>      then
>          System.out.println("My Value : " + $testDrools.getMyValue() );
> end
> 
> Is it normal that in my second rule is verified ?
> -> eval( $testDrools.getMyValue().equals("") ) is true
> but : System.out.println("My Value : " + $testDrools.getMyValue() ); 
> show me that myValue == 1
> 
> Perhaps I did something wrong ?
> 
> Thanks for your helping me.
> N.
> 
> 
> 
> PS : Here is me TestDroolsDto :
> public class TestDroolsDto {
>      private String myValue;
> 
>      public TestDroolsDto() {
>          myValue="";
>      }
> 
>      public String toString() {
>          return " --> " + myValue;
>      }
> 
>      /**
>      * @return the myValue
>      */
>     public String getMyValue() {
>         if ( myValue == null ) {
>             myValue = "";
>         }
>         return myValue;
>     }
> 
>      /**
>      * @param myValue the myValue to set
>      */
>     public void setMyValue( String myValue ) {
>         this.myValue = myValue;
>     }
> }
> 
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 


--
View this message in context: http://drools.46999.n3.nabble.com/rules-users-Question-problem-tp2931057p2931186.html
Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list