File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Java Products and Servers and the fly likes Question about shadow fact and java objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "Question about shadow fact and java objects" Watch "Question about shadow fact and java objects" New topic

Question about shadow fact and java objects

Hope Zhu
Ranch Hand

Joined: May 11, 2004
Posts: 32
I have a normal java object, not a javabean, which I want to use in Jess fact. Is shadow fact the right way to go? It did not work for me. I got an error msg, "no such slot fltnum in template Main: ata" after I type in defrule. Below is my code in Java & Jess.

in Java:
public class FltData {
private int fltnum;
public void setFltNum(int i) {fltnum = i;}
public int getFltNum() {return fltnum;}

in Jess:
(defclass data FltData)
(definstance data (new FltData) static)
(defrule simple_rule
(data (fltnum ?x))
(printout t ?x crlf))

Please help. Thanks in advance.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

Hi Hope,

By Jess's very minimal standards, FltData is a perfectly good JavaBean class.

The problem, if your code is exactly as shown, is that Jess is case sensitive, and uses the JavaBeans standard for naming properties, according to which a method getFltNum gives rise to a property "fltNum", not "fltnum", with a capital "N".

You can see the property names by displaying the deftemplate that Jess creates from your Bean class (using the name "data" that you used in the defclass

(ppdeftemplate data)

This should show a slot named "fltNum", along with other ones.

[Jess in Action][AskingGoodQuestions]
Hope Zhu
Ranch Hand

Joined: May 11, 2004
Posts: 32
Hi Ernest,

It works. Thanks a lot for all your help.

I have a further question about using java objects in the LHS of a rule, hope you can help me out again. FltData is only a simple java object. In the real world my java object is far more complicated than FltData. I have a object which has one object, one hashset and a string in it. Inside the hashset are two diff kind of objects. Do you think it's possible to use some of the data from the hashset as LHS of a rule? Too many layers I am lost.

Thanks in advance.
I agree. Here's the link:
subject: Question about shadow fact and java objects
Similar Threads
rules and querys
Take too long to call reset
need help:dos based .clp to java gui
Using java object in LHS of a Jess rule failed
[Jess] Exchanging values between Java and Jess