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<majeed@pobox.com>");
InternetAddress[] cc = new InternetAddress[1];
cc[0] = new InternetAddress("Mohit M. Sant<mohitsant@hotmail.com>");
InternetAddress[] bcc = new InternetAddress[1];
bcc[0] = new InternetAddress("Abdul Majeed Ghadialy<majeed@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
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.
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…
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.
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.