Thanks Edson,

BTW, I've tried to instantiate an internal fact in a rule with MVEL dialect but it didn't worked. I've tried this in M4. I' haven't tried it yet in M5.

Is this a known issue or should I create a new JIRA with test case?

Best Regards,
Michal


On Tue, Jan 27, 2009 at 2:31 PM, Edson Tirelli <tirelli@post.com> wrote:
 
   Michal is correct from the point of view of the application. That is required because the actual classes are generated at compile time and not visible to the application classpath.
  
   Although, that is not the only way. Inside your rules, they are visible and you instantiate them the same way as you instantiate any other java Pojo:

rule xyz
when
     // sometihng
then
     Person p = new Person();
     p.setName( "Bob" );
     insert( p );
end

    Also, if you use Guvnor to define your model, Guvnor is capable of generating a jar file for you with the generated classes. This way you can download the jar and add it to the classpath of your application and use it as any POJOs too.

    []s
    Edson


2009/1/27 Michal Bali <michalbali@gmail.com>

Look at this unit test for some examples:

        // Retrieve the generated fact type
        FactType cheeseFact = ruleBase.getFactType( "org.drools.generatedbeans.Cheese" );

        // Create a new Fact instance
        Object cheese = cheeseFact.newInstance();

        // Set a field value using the more verbose method chain...
        // should we add short cuts?
        //        cheeseFact.getField( "type" ).getFieldAccessor().setValue( cheese,
        //                                                             "stilton" );

        cheeseFact.set( cheese,
                        "type",
                        "stilton" );
        assertEquals( "stilton",
                      cheeseFact.get( cheese,
                                      "type" ) );


On Tue, Jan 27, 2009 at 2:02 AM, Oleg Zenzin <zenzin@intalio.com> wrote:

There's now possibility to declare facts in the drl, like:

declare Person
 name: String
 age: int
end

My question is how do I instantiate this fact object during runtime? Do I still need to have class Person compiled and existing somewhere in classpath, or there's a helper class which I can use "fake the fact", something like:

  FakeFact person = FakeFact("Person");
  person.setField("name", "Oleg");
  person.setField("age", "42");
  session.insert(person);

Or there's another nicer way?

Thank you,
-Oleg Zenzin


_______________________________________________
rules-dev mailing list
rules-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev



_______________________________________________
rules-dev mailing list
rules-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev




--
 Edson Tirelli
 JBoss Drools Core Development
 JBoss, a division of Red Hat @ www.jboss.com

_______________________________________________
rules-dev mailing list
rules-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev