• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question about shadow fact and java objects

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Hope Zhu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic