I'm working on Flex application and I need to open a Java Applet from Flex (e.g. clicking a button). In particular I'd like to open imageJ, a particular imaging program that could work as application, applet or be integrated in a web page. Is there a way to call it from Flex? I've seen a couple of tutorials that explain how to call a single function in another Java file from Flex, but I'm not so sure that it is what I'm looking for.
Thanks for your answers,
cheers,
David
I don't know if there's a better way, but if I was doing it, I'd write a JavaScript function that would load the Java applet (could be as simple as document.write("<object …>")), then use Flex's ExternalInterface to call that JavaScript.
Expose a public method in your applet, which the flex would call. You could load the applet the following way. It is a sample program, to call java methods and get a value from java, you can do changes as per your need
<object
id = "MyApplet"
name = "Some name"
classid = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="0" height="0">
<PARAM NAME = "CODE" VALUE = "com.my.applet.MyApplet.class" >
<PARAM NAME = "CODEBASE" VALUE = "." >
<PARAM NAME = "ARCHIVE" VALUE = "applet-client.jar" >
<PARAM NAME = "cache_option" VALUE="No">
<PARAM NAME = "java_version" VALUE="1.6+">
<param name = "type" value = "application/x-java-applet;version=1.6">
<comment>
<embed
name = "MyApplet"
type = "application/x-java-applet;version=1.6" \
CODE = "com.my.applet.MyApplet.class" \
JAVA_CODEBASE = "." \
ARCHIVE = "applet-client.jar"
cache_option = "No"
scriptable = false
pluginspage = "http://java.sun.com/products/plugin/index.html#download"
width="0" height="0"
>
<noembed>
</noembed>
</embed>
</comment>
</object>
With the above in your html file( I am not explaining everything) , the applet will be downloaded and ready to use. Now on click of a button on your flex app, you should have something like below.
var returnedStringFrom java:String=ExternalInterface.call("document.MyApplet.functionInJava",stringParam);
Note : MyApplet is the name in the object declaration above, the functionInJava is a public function in the the java class com.my.applet.MyApplet. It takes a parameter and returns a string parameter. The Java program will look like below.
package com.my.applet;
public class MyApplet{
//other methods..
public String functionInJava(String stringpm){
// your implementation
return "SomeString";
}
}
Happy coding.
Related
This question is about structure :
I have a Default.aspx page which holds references to (XML)services, and handles innerHTML of HTML objects. The ammount of buttons is based on services output.
Since this is an long and complex algorithm, I would like to encapsulate this in another class, to divide it into smaller and more readable chunks of code.
The problem is I do not know what the best option is, should I copy the reference of the used objects(service as well as the HTML items) into the new class ?
Since the ammount and origin of items it does not look to my like an elegant option.
I searched on the internet but could not find anything that suits this(I would think) common situation
This is the function I would like to transfer to another class. Currently it is in Default.aspx
and uses rep(ort)Service,defaultPath,path,selectionScreen and Image2 objects to draw the menu dynamically.
''' <summary>
''' Dynamically builds the square menu where the reports can be selected from.
''' It is based on the number of reports available
''' Show list of available reports on reporting server as HyperLinks
''' </summary>
''' <remarks></remarks>
Private Sub BuildReportSelectionArea(Optional path As String = "")
Dim items As CatalogItem() = repService.ListChildren(path, False)
Dim items2 As CatalogItem() = repService.ListChildren(path, False)
'Ensure that folders are shown first
Dim maxFolder = 0
For i = 0 To items.Count - 1 Step 1
If (items(i)).TypeName = "Folder" Then
items(i) = items2(maxFolder)
items(maxFolder) = items2(i)
maxFolder += 1
End If
' Some other code
End Sub
'TODO :Ensure the alfabetical order is preserved
Next
I would first generally comment on the code:
this means you are 2 times accessing the service, but the second array is later used to "sort" the items catalogItem, it seems a waste of resources to call the service twice
Dim items As CatalogItem() = repService.ListChildren(path, False)
Dim items2 As CatalogItem() = repService.ListChildren(path, False)
Reordering you could simply achieve using
Dim items As New List(Of CatalogItem)(RepService.ListChildren(path, False))
items.Sort(Function(item1 As CatalogItem, item2 As CatalogItem)
If String.Equals(item1.TypeName, item2.TypeName) Then
Return item1.FileName.CompareTo(item2.FileName)
End If
If item1.TypeName = "Folder" Then
Return -1
End If
Return 1
End Function)
which would sort by folders first, then by filename (you might have to update some of your properties to match)
you could further extract by either creating a module or a shared class that accepts the repService as an attribute and the path, and returns your output code
though creating a user control / webpart so you could add this functionality to each page you would like, would be a very good option as well, and the generally accepted way to refactor complex code...
I am attempting to create a DocuSign envelope from a template document using the CreateEnvelopeFromTemplates method, available within their v3 SOAP API web service. This is being instantiated from a asp.NET v4.0 web site.
Upon calling the method armed with the required parameter objects being passed in. I am recieving an exception from the web service, basically telling me that the Template ID is not a valid GUID.
669393: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
Line 14889:
Line 14890: public DocuSignDSAPI.EnvelopeStatus CreateEnvelopeFromTemplates(DocuSignDSAPI.TemplateReference[] TemplateReferences, DocuSignDSAPI.Recipient[] Recipients, DocuSignDSAPI.EnvelopeInformation EnvelopeInformation, bool ActivateEnvelope) {
Line 14891: return base.Channel.CreateEnvelopeFromTemplates(TemplateReferences, Recipients, EnvelopeInformation, ActivateEnvelope);
Line 14892: }
Line 14893:
The template reference, a guid. Must be specified as the "Template" string property against TemplateReference object. This is then added to a dynamic array of TemplateReferences, which is one of the input parameters of the CreateEnvelopeFromTemplates method.
Actual template GUID: f37b4d64-54e3-4723-a6f1-a4120f0e9695
I am building up my template reference object using the following function that i wrote to try and make the functionality reusable:
Private Function GetTemplateReference(ByVal TemplateID As String) As TemplateReference
Dim templateReference As New TemplateReference
Dim guidTemplateID As Guid
With TemplateReference
.TemplateLocation = TemplateLocationCode.Server
If Guid.TryParse(TemplateID, guidTemplateID) Then
.Template = guidTemplateID.ToString
End If
End With
Return TemplateReference
End Function
The TemplateID is being passed in from a appSetting configuration value at the time of the TemplateReferences array instantiation like so...
templateReferences = New TemplateReference() {GetTemplateReference(ConfigurationManager.AppSettings("DocuSignTemplate_Reference"))}
recipients = New Recipient() {AddRecipient("myself#work.email", "My Name")}
envelopeInformation = CreateEnvelopeInformation()
envelopeStatus = client.CreateEnvelopeFromTemplates(templateReferences, recipients, envelopeInformation, True)
As you can see from my GetTemplateReference function I am also parsing the GUID before setting it back as a string so i know its valid. The template is managed and stored at the DocuSign end, hence specifying the document location.
I am referring to their own documentation:
CreateEnvelopeFromTemplates
Why oh why is the method not liking my Template ID? I can successfully use their REST API to call the same method, using their own code samples. Worst case I can make use of this but would rather interact with the web service as I would need to construct all the relevent requests in either XML or JSON.
I would really appreciate if someone could perhaps shed some light on this problem.
Thanks for taking the time to read my question!
Andrew might be spot on with the AccountId mention - are you setting the AccountId in the envelope information object? Also, have you seen the DocuSign SOAP SDK up on Github? That has 5 sample SOAP projects including one MS.NET project. The .NET project is in C# not Visual Basic, but still I think it will be helpful to you. Check out the SOAP SDK here:
https://github.com/docusign/DocuSign-eSignature-SDK
For instance, here is the test function for the CreateEnvelopeFromTemplates() function:
public void CreateEnvelopeFromTemplatesTest()
{
// Construct all the recipient information
DocuSignWeb.Recipient[] recipients = HeartbeatTests.CreateOneSigner();
DocuSignWeb.TemplateReferenceRoleAssignment[] finalRoleAssignments = new DocuSignWeb.TemplateReferenceRoleAssignment[1];
finalRoleAssignments[0] = new DocuSignWeb.TemplateReferenceRoleAssignment();
finalRoleAssignments[0].RoleName = recipients[0].RoleName;
finalRoleAssignments[0].RecipientID = recipients[0].ID;
// Use a server-side template -- you could make more than one of these
DocuSignWeb.TemplateReference templateReference = new DocuSignWeb.TemplateReference();
templateReference.TemplateLocation = DocuSignWeb.TemplateLocationCode.Server;
// TODO: replace with template ID from your account
templateReference.Template = "server template ID";
templateReference.RoleAssignments = finalRoleAssignments;
// Construct the envelope information
DocuSignWeb.EnvelopeInformation envelopeInfo = new DocuSignWeb.EnvelopeInformation();
envelopeInfo.AccountId = _accountId;
envelopeInfo.Subject = "create envelope from templates test";
envelopeInfo.EmailBlurb = "testing docusign creation services";
// Create draft with all the template information
DocuSignWeb.EnvelopeStatus status = _apiClient.CreateEnvelopeFromTemplates(new DocuSignWeb.TemplateReference[] { templateReference },
recipients, envelopeInfo, false);
// Confirm that the envelope has been assigned an ID
Assert.IsNotNullOrEmpty(status.EnvelopeID);
Console.WriteLine("Status for envelope {0} is {1}", status.EnvelopeID, status.Status);
}
This code calls other sample functions in the SDK which I have not included, but hopefully this helps shed some light on what you're doing wrong...
This problem arises when you don't set up the field AccountId. This field can be retrieved from your account. In Docusign's console go to Preferences / API and look here
Where to find AccountID Guid in Docusign's Console
Use API Account ID (which is in GUID format) and you should be OK.
I'm planning to create a multilingual app in Flex. My approach is kind of the following:
To have an XML with all the phrases in application...
<mx:Script>
<![CDATA[
public var selectedLanguage : String = "spanish";
public var language : xml =
<xml>
<message id="<<hashcode of the string in english>>" english="hello world" spanish="hola mundo" french="bonjour tout le monde"/>
<message id="<<hashcode of the string in english>>" english="good bye every body" spanish="adios a todos" french="tout le monde au revoir"/>
</xml>;
//Then a function to make the translation:
public function translate(msg:String):String{
//Maybe not a hashCodeFunction but some function to return an unique code for every string
var hashcode : int = hashCodeFunction(msg);
var translation : String = language.message.(#id==hashcode)[selectedLanguage];
if(translation==null) return msg;
return translation;
}
]]>
</mx:Script>
<mx:Button label="translate('hello world')"/>
Well, the xml could be structured in a different way but what I want is create all labels like "translate('some text')" because in this way I think is better at programmer time, and at the end of the development process just create a "pre processor" that is going to look for ALL strings in source code like "translate('some text')" and extract 'some text' then calculate the hash code and append it to xml, and when xml is ready all the application is going to be multilingual.
I want to know if someone has another approach to share.
Adobe implements Resource Bundles for localization and internationalization of text and images.
Compiler options may be specified to include locales:
-locale=en_US,ja_JP,fr_FR
Then, locale specific properties may be retrieved such as:
<s:Label text="{resourceManager.getString('bundleName', 'key')}" />
References:
Adobe Introduction to localization
Flex 4 Localization Quick Start
Introduction to Flex Resource Bundles
Localizing a Flex library with multiple languages in one .swc file
Following on from my earlier question about creating Address Books (many thanks Peter!), I have a small throw-away console application doing just that and working great - but in addition I'm trying to update the metadata of a Keyword with the Item Id of the created Address Book.
Slightly shortened snippet ...
StaticAddressBook ab = new StaticAddressBook();
ab.Title = title;
ab.Key = key;
ab.Save();
// id is a correct Keyword TCM ID
Keyword k = tdse.GetObject(id, EnumOpenMode.OpenModeEdit);
if (k != null)
{
k.MetadataFields["addressbookid"].value[0] = ab.Id.ItemId;
k.Save(true);
}
I keep getting the following error on Save():
XML validation error. Reason: The element 'Metadata' in namespace
'uuid:2065d525-a365-4b45-b68e-bf45f0fba188' has invalid child element
'addressbookid' in namespace
'uuid:2065d525-a365-4b45-b68e-bf45f0fba188'. List of possible elements
expected: 'contact_us_email' in namespace
'uuid:2065d525-a365-4b45-b68e-bf45f0fba188'
But I know the Keyword has the correct Metadata assigned, (thats why I don't bother checking!). Shortened Tridion XML from a current keyword in question:
<tcm:Keyword>
<tcm:Data>
<tcm:MetadataSchemaxlink:type="simple"xlink:title="IP.Location.Metadata" xlink:href="tcm:49-2142-8" />
<tcm:Metadata>
<Metadata xmlns="uuid:2065d525-a365-4b45-b68e-bf45f0fba188">
<email>...</email>
<addressbookid>3</addressbookid>
<contact_us_email>...</contact_us_email>
<request_a_sample_email>...</request_a_sample_email>
<webinar_feedback_email>....</webinar_feedback_email>
</Metadata>
</tcm:Metadata>
<tcm:IsRoot>true</tcm:IsRoot>
</tcm:Data>
</tcm:Keyword>
Have I missed something can Keyword metadata not be updated in this way?
I guess I could look at the Core Service to update Keywords, but it seemed to to make sense to do everything within this application.
UPDATE
Order was key here, strangely!
The following code works:
ItemFields fields = k.MetadataFields;
System.Diagnostics.Debug.WriteLine(fields.Count);
string email = fields[1].value[1];
string contact = fields[3].value[1];
string request = fields[4].value[1];
string webinar = fields[5].value[1];
fields[1].value[1] = email;
fields[2].value[1] = ab.Id.ItemId;
fields[3].value[1] = contact;
fields[4].value[1] = request;
fields[5].value[1] = webinar;
k.Save(true);
Got caught out by the non-0-based index when getting/setting values and had to reassign existing fields back, in order.
Cheers
It seems that the order of the fields has changed in the Schema since that Component was created. At least the Schema expects contact_us_email in the position where you current have addressbookid.
There may be other changes, so I'd verify the order of fields in the Schema and make sure the Component(s) match, before you run your tool.
I am using Flex to connect to a Rest service. To access order #32, for instance, I can call the URL http://[service]/orders/32.
The URL must be configured as a destination - since the client will connect to different instances of the service. All of this is using the Blaze Proxy, since it involves GET, PUT, DELETE and POST calls.
The problem is:- how do I append the "32" to the end of a destination when using HttpService? All I do is set the destination, and at some point this is converted into a URL. I have traced the code, but I don't know where this is done, so can't replace it.
Options are:
1. Resolve the destination to a URL within the Flex client, and then set the URL (with the appended data) as the URL.
2. Write my own java Flex Adapter that overrides the standard Proxy, and map parameters to the url like the following: http://[service]/order/{id}?id=32 to http://[service]/order/32
Has anyone come across this problem before, and are there any simple ways to resolve this?
Just so everyone knows, this is how I resolved this issue:
I created a custom HTTPProxyAdapter on the server
public MyHTTPProxyAdapter extends flex.messaging.services.http.HTTPProxyAdapter {
public Object invoke(Message message) {
// modify the message - if required
process(message);
return super.invoke(message);
}
private void process(Message message) {
HTTPMessage http = (HTTPMessage)message;
if(http != null) {
String url = http.getUrl();
ASObject o = (ASObject)http.getBody();
if(o != null) {
Set keys = o.keySet();
Iterator it = keys.iterator();
while(it.hasNext()) {
String key = (String)it.next();
String token = "[" + key +"]";
if(url.contains(token)) {
url = url.replace(token, o.get(key).toString());
o.remove(key);
}
}
http.setUrl(url);
}
}
}
}
Then replaced the destination adapter to my adapter.
I can now use the following URL in the config.xml and anything in square brackets will be replaced by the Query string:
<destination id="user-getbytoken">
<properties>
<url>http://localhost:8080/myapp/public/client/users/token/[id]</url>
</properties>
</destination>
In this example, setting the destination to user-getbytoken and the parameters {id:123} will result in the url of http://localhost:8080/myapp/public/client/users/token/123
Here's a simple way to resolve the url to the HTTPService within Flex via the click event's handler.
here's a service:
<mx:HTTPService
id="UCService"
result="UCServiceHandler(event)"
showBusyCursor="true"
resultFormat="e4x"
/>
Then here's the handler:
private function UCmainHandler(UCurl:String) {
UCService.url = UCurl;
UCService.send();
}
And here's a sample click event:
<mx:Button label="add to cart" click="UCmainHandler('http://sampleurl.com/cart/add/p18_q1?destination=cart')" />
Of course you could pass other values to the click handler, or even have the handler add things to the url based on other current settings etc...
Hope that helps!