Accessing functions not listed in the bean

When I place a bean on a form there are certain properties and methods exposed.

However, some of those methods are not shown. Does this mean I can’t use them?

I’m working with the Alphaworks SMTP bean (IBM) and I’m trying to access certain methods. For example the .jar file and the docs point to

com.ibm.network.mail.base.MimeMessage

to do things like the following code.

Java Code - not Javascript

MimeMessage msg = new MimeMessage();
       

       String fileName = "mail.txt";
       MimeBodyPart part = new MimeBodyPart(new FileInputStream(fileName));
       part.addHeader(Constants.contentType, "text/plain");
       part.setEncoding(MimePart.BASE64);
       part.setDisposition(MimePart.INLINE);
       

       msg.setContent(part, "");
       msg.addHeader("Subject", "Test Mail");
       

       InternetAddress[] to = new InternetAddress[1];
       to[0] = new InternetAddress("Abdul Majeed Ghadialy&ltmajeed@pobox.com>");
       

       InternetAddress[] cc = new InternetAddress[1];
       cc[0] = new InternetAddress("Mohit M. Sant&ltmohitsant@hotmail.com>");
       

       InternetAddress[] bcc = new InternetAddress[1];
       bcc[0] = new InternetAddress("Abdul Majeed Ghadialy&ltmajeed@vnet.ibm.com>");
       

       msg.addRecipients(MimeMessage.TO, to);
       msg.addRecipients(MimeMessage.CC, cc);
       msg.addRecipients(MimeMessage.BCC, bcc);

I know I can’t create a new MimeMessage() in the Javascript method - or can I somehow?

Can I get a Servoy developer to help me work out some things with these beans? I’ll promise to continue the education and do it in a great manner! This will make your work easier with people educating other people - which you don’t have to pay :wink:

Matt, I guess this is doable I will see what I can come up with this evening…

Hi Marcel,

What did you come up with?

Thanks

first of all new MimeMesssage() is not a method, it is a constructor.
And we don’t place them in the tree as moveable codes because normally you don’t make beans. You place them on a form.

But calling the constructor should also work but is not supported!
But you have to use the complete classname. (don’t currently know the package of that mimemessage so this is a guess!!)

var messge = new org.alphaworks.popbean.MimeMessage()

But this is not what you really want to do. What you really need for such a bean is that is is wrapped in a special servoy bean or plugin that hides most of those lines of java code for you.

Thanks for your explanation.

It means that I do not necessarily need to place the bean in the form although it is not recommended. I could directly create a new instance of it from my method. Also when I place a bean in the form I can see some properties for that when I clicked on it. Are those properties parameters for its constructor? Just to know…

Thanks

no those properties are for setting or getting values of the current instance of the bean.

ok thanks. Actually I do not have much knowledge about java. I am trying learn it..

Hi Johan,

I am using the elegant jbean SMTP bean.

I am trying to create a new instance using the following code according to your advice:

msg = com.elegantj.net.message.MIMECompliantMessage();

But I am getting the error

ReferenceError: “com” is not defined

Any Idea why I am getting this?

Thanks

try:

msg = new com.elegantj.net.message.MIMECompliantMessage();

Tried that. But getting the same error.

Any other suggestion please?

Thanks

Did you check your classpath settings? I sounds like the JVM cannot find the bean .jar file.

You can specify the classpath in your app startup params (in the batch file, or other script used to start Servoy). Just add the parameter -classpath “<path_to_SMTP_bean_here>” after the java (or javaw) command.

example:

java -classpath "c:\smtpbean.jar; servoy_developer.jar Servoy

or

java -classpath <other cp files>;c:\smtpbean.jar com.servoy.j2db.server.ApplicationServer

Hi,

I am using the following code to startup the servoy

java -classpath D:\ejnetwork_v1\ElegantJNetwork\jars\smtpclient.jar;D:\ejnetwork_v1\ElegantJNetwork\jars\message.jar;servoy_developer.jar Servoy

But I still have the same problem.

Any idea please??

Thanks

Hi Johan & fdoddridge,

Any idea why I am getting this?

I have no problems accessing the native java constructor or methods like for example:

myColor = new java.awt.Color(1, 1, 1);

Thanks

when you want to access a java class that doesn’t begin with java.* package.
you have to specify that in front of it:

var messge = new Package.org.alphaworks.popbean.MimeMessage()

The problem is that this still doesn’t work directly in the developer when you load the beans by just dropping them in the bean dir. (you have to add them to the classpath)
In the client this works fine. I fixed this also for the developer that it just works without tricks. This will be in the next maintenance release.

This is cool.

I will try this now

Thanks

var msg = new Package.com.elegantj.net.message.MIMECompliantMessage();

I tried the above one but it gives me “Package” is not defined error.

I use the following command to start the servoy

java -classpath D:\ejnetwork_v1\ElegantJNetwork\jars\message.jar;servoy_developer.jar Servoy

just to finisch this thread:
it is Packages.xxx (so plural)

Thanks!

Got this working a long time ago.