dynamic value pass to applet based on dropdown value selection - applet

I have to pass value dynamically to applet so that it can pick correct xml from resource based on the value selected from the dropdown .
<applet code="com.vaannila.utility.dynamicTreeApplet.class" archive="./appletjars/dynamictree.jar, ./appletjars/prefuse.jar" width ="1000" height="500" >
</applet>
How can i do that .

You can handle this by writing a public method in your applet
let's assume
void setXmlName(String xmlName);
you can access this method from java script .. for example this java script method
function updateXmlName(value){
/* Get an object of the applet .. make sure the at 'id' attribute has the 'myappletid' value. */
var myApplet = documents.applets["myappletid"];
myApplet.setXmlName(value);
}
update your dropbox HTML
<select id="optionList" onchange="updateXmlName(document.getElementById('optionList').value);>
I hope this could help you.

If you choose a value from dropdown and then send it to the page with applet then used simple <param> tag (as described here). If you want to do it dynamically, then you can invoke java methods via javascript as described here.

Related

In an Office Addin Is it possible to specify image just from ribbon xml?

I started by creating xml from the ribbon designer. I already have a resource file containing button images.
I got lines like
<button id="btnInsEq2" onAction="BtnInsEq2_Click" showLabel="false" />
which I changed to
<button id="btnInsEq2" onAction="BtnInsEq2_Click" image="InsEquation2" showImage="true" showLabel="false" />
There is some image called InsEquation2 in my resource file, which is accessible at runtime. I tried many variations on "InsEquation2" including the full path of the file. Nothing works.
I see answers where images are loaded in code. Is that really necessary or can I do it simpler in the xml?
By the way a line like
<button id="btnInsEq3" onAction="BtnInsEq3_Click" imageMso="Bold" label=" " showLabel="false" />
works fine. But I dont want B!
I would use the getImage tag like:
<button id="btnInsEq2" onAction="BtnInsEq2_Click" showLabel="false" getImage="GetImage"/>
which requires a callback. Assuming you write in C# it could look something like:
public Bitmap GetImage(Office.IRibbonControl control)
{
return new Bitmap(Properties.Resources.RelevantImage);
}
There are two ways for loading images in the Ribbon XML.
The getImage callback for each element where it is supported.
The loadImages callback for the customUI element where all images are loaded.
So, if you want to specify image names in the ribbon XML markup you need to implement the loadImages callback for the customUI element.
The <customUI> element's loadImage attribute enables you to specify a callback that can load all images. After you set up this callback procedure, Office calls the callback procedure and passes the string from the image attribute for each control that loads images. You do not need to implement the getImage callback multiple times, such as one time for each control that requires images. For example, a customization might include markup like the following.
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
loadImage="GetImage">
<!-- Later in the markup -->
<button id="myButton" image="mypic.jpg" />
To supply the button's image, Office calls the GetImage function. It passes the parameter "mypic.jpg" and expects an IPictureDisp object in return. By using this technique, you can write a single callback procedure that returns all the images your customization needs, without having to write each individual control's getImage callback. Note that the loadImage callback is not called again when you call the Ribbon's Invalidate method or InvalidateControl method. For the controls that need to change images dynamically at run time, use the getImage callback.
So now I have found out what to put in the GetImage function suggested by #EugeneAstafiev . Basically you need to iterate through the resources and find the one indicated by the imageId input parameter. Here it is in XML / VB
<customUI xmlns="http://schemas ... loadImage="GetButtonImages" >
..
<group id="InsertEquations" label="Add" image="InsEquation">
<button id="btnInsEq2" onAction="BtnInsEq2_Click" image="InsEquation2"/>
Public Function GetButtonImages(imageId As String) As Bitmap 'was IPictureDisp as specified in documenation
'enumerate resources ...
'see https://stackoverflow.com/questions/4656883/how-enumerate-resources-inside-a-resx-file-programmatically
Dim ErrorBitmap As New Bitmap(My.Resources._Error)
Dim ResMan As New ResourceManager("EquationAcc.Resources1", Assembly.GetExecutingAssembly)
Dim ResSet As ResourceSet
ResSet = ResMan.GetResourceSet(CultureInfo.CurrentCulture, True, True)
For Each Item As DictionaryEntry In ResSet
'Debug.WriteLine(item.Key) 'appears in window from Debug / windows / output
If Item.Key = imageId Then
Return Item.Value
End If
Next
Return ErrorBitmap
End Function
Also needed Imports System.Drawing, .Collections, .Globalization, .Reflection, .Resources
for declarations and
.Diagnostics, stdole for some now unused declarations
EquationAcc is the project, Resources1.resx the resource file
If there is a better way I'd love to know.

AEM: How to dynamically get the current page path and pass it to the request parameter for drop down

options=/bin/services/myservlet.GET_DROPDOWN_VALUES.json?locale='some_locale'
if I put locale=en-us it works fine,
How can I dynamically get the current page locale and pass it to the request parameter ?
So, your servlet requires locale as one of the parameters to retrieve dropdown values. I can think of 2 options to do this.
Invoke the servlet with $Path as one of the parameters. $Path will give you the complete page path, all the way till jcr:content. options=/bin/services/myservlet.GET_DROPDOWN_VALUES.json?compNode=$PATH.
In your servlet, construct page object using $PATH, then as #jwepurchase mentioned, get the locale using page.getLanguage(false).
String compNodePath = (String) request.getParameter("compNode");
String pagePath = StringUtils.substringBefore(compNodePath, "jcr:content");
PageManager pageMgr = request.getResourceResolver().adaptTo(PageManager.class);
Page page = pageMgr.getContainingPage(pagePath);
Locale pageLocale = page.getLanguage(false);
getLanguage will look for jcr:language property in currentpage or its ancestors. This property gets set when you set the Language field in page properties (advanced tab) of your page(usually set in the root locale page) to an appropriate value. eg: If you set the language to english(us), jcr:language will be en_us.
Similar steps as option 1, if value in page property is not set, you can use currentPage.getAbsoluteParent(DEPTH_VAL) to retrieve the locale value. Not a recommended soln though.
com.day.cq.wcm.api.Page.getLanguage(false) will return the value of the jcr:language property on the page or the first parent page where it is sent. Generally this isn't set on every page.
If you have included Adobe's global.jsp or used the <cq:defineObjects/> tag in your JSP, you should find that "currentPage" is already in scope, providing access to a Page object.
I generally have a custom taglib function to make it easier to access via EL. But as a scriptlet I expect the following would work:
<%= ((Page)getPageContext().getAttribute("currentPage")).getLanguage(false)%>

Given a Path get a reference to the Resource in Sightly

The component dialog has a pathfield widget where the authors can set a page path. In the Sightly component, I would like to look up that page resource and get (and display) properties from it.
The dialog...
<linkedPathLocation jcr:primaryType="cq:Widget"
fieldLabel="Linked Path"
name="./linkedPathLocation"
xtype="pathfield"
fieldDescription="Select a page. URL, Title, Description and Image are properties of the selected page"/>
The component code I would like to work (it's not).
<div class="row" data-sly-resource.page = "${properties.linkedPathLocation}">
<h1 >${page.title}</h1>
<p>${page.description}</p>
</div>
My question: Is there a way in Sightly to resolve and use some resource from a given path? If not, I could create a USE-API class and to do the following...
Page page = resourceResolver.resolve("/path/to/resource").adaptTo(Page.class);
I feel there should be a better answer which allows resources to be resolved directly from the Sightly, but the following USE-API solution works if not...
Java Use Class
public class PageHelper extends WCMUsePojo {
String pagePath = "";
#Override
public void activate() {
pagePath = get("path", String.class);
}
public Page getPage() {
return this.getPageManager().getPage(pagePath);
}
}
The component Sightly...
<div class="row" data-sly-use.linkedPage = "${'com.package.PageHelper' # path = properties.linkedPathLocation}">
<h1 >${linkedPage.page.title}</h1>
<p>${linkedPage.page.description}</p>
</div>
What you are trying to do, in essence, is render a Resource within the context of the rendering of another Resource. data-sly-resource seems the appropriate attribute to use, but instead of attempting to nest additional elements into the element containing the data-sly-resource you should define another Sightly .html file which dictates how the nested resource is to be rendered.
Let us say that your Resource is of type application/components/content/type. Within type.html you might have the following statement
<sly data-sly-resource="${properties.linkedPathLocation} # resourceType='application/components/content/type/subtype' />
You would then be able to define /apps/application/components/content/type/subtype/subtype.html containing the rendering to produce which would be invoked in the context of the Resource identified by your path.
The main purpose of Sightly templates is separation of responsibility (frontend & backend) so that we can have simple, clean and beautiful html markup which is designer friendly and easily readable.
For your case, writing a Class (Java/Javascript) to process dialog information, and supply it back to Sightly template is correct way. Read here for more details.

How to detect the browsers language in the EntryPoint SmartGWT

I'm developping a project with SmartGWT and I want to make it international,but how to know the browser's language in my EntryPoint (onModuleLoad) ?
I'm using Spring in the Server Side, and in my onModuleLoad I'm sending an RPC call to my Service which is gathering data from properties Files and respond with a Map contains all my keys value for internationalization, so while creating IU Widgets I'm using my Map like this lables.get("myLabel").
now that everytings is working fine, I want to detect the browser's language and use it for querying the right properties.
Sorry if my english is so bad
com.google.gwt.i18n.client.LocaleInfo#getCurrentLocale()
then I ended with a dirty solution, I created a javascript function as Lt_Shade told me,which put the navigator.language, then I retreive it in my EntryPoint thanks to the Document object, the probleme was when I run with IE or FireFox, the EntryPoint run before my HTML Page, so before my Javascript function and I dont find my navigator.language, so what I did is to create a JSNI function which call my javascript object within my EntryPoint (Calling Javascript function from java:gwt code) so I emphasize and insist the call then I'l sure that my navigator.language is loaded and I can retreive it.
in my HTML page
....
<script language="javascript">
function loadLocaleLanguage(){
document.getElementById("localeLanguage").setAttribute("value",(navigator.language).substring(0,2); // I don't need Country code
}
</script>
...
<input type="hidden" id="localeLanguage" value="" />
....
in my EntryPoint
public static native void getLocaleLanguage() /*-{
$wnd.loadLocaleLanguage();
}-*/;
public void onModuleLoad(){
// I call my javascript function to ensure that the input have my localeLanguage
getLocaleLanguage();
// now I'm retreiving it using DOM thanks to Document object
String localeLanguage = Document.get().getElementById("localeLanguage").getAttribute("value");
....
}
I'm sure that's not the best solution but at least it works
if someone can help me find how to acces the httpRequest within the EntryPoint (it containts the accept-language) or to directly acces the navigator.language in the EntryPoint, it'll be better.
thanks guys
I am not sure if this helps but there is a question like this which includes some java code for getting the language in a Java servlet.
Automatically selecting country and language for user in Java Servlet
You could also try add a JavaScript function into your EntryPoint something like
var userLang = (navigator.language) ? navigator.language : navigator.userLanguage;
alert ("The language is: " + userLang);

How Do I Use GWT As An External Component Engine?

For example, suppose I want to show a CellTable on my page. I want to define the rows & columns for this cell table in Javascript, provide a datasource, and then call a GWT method that would inject this cell table into the page and make an AJAX call to populate it with data.
It's important to note that my app already exists in its own war and deployed on the server - I want to deploy a another GWT app war and be able to call the javascript from my application and pass arguments to it (through javascript, for example) so that I can customize my CellTable columns and contents.
The problem is that a GWT application has one entry point and it doesn't accept any arguments - meaning I have to build my customized CellTable using some data that I plant on the html page and then extract inside onModuleLoad(). Doing this seems dumb as I would have to effectively code some kind of input/output language and parse it on my own, such as:
// entry point
public void onModuleLoad() {
// Create a CellTable.
CellTable<Data> table = new CellTable<Data>();
// suppose we have a hidden element on the HTML page which has the column information for our cell table, i.e. <input type="hidden" id="SomeHiddenFieldValueWithInputs" value="Column1|Column2"/>
RootPanel cellTableMetaData = RootPanel.get("SomeHiddenFieldValueWithInputs") ; // suppose the value of this is Column 1|Column2
String tableColumns = cellTableMetaData.getElement().getAttribute("value");
String[] columns = tableColumns.split("|");
for(String columnName:columns)
{
// Add a text column to show the name.
TextColumn<Data> column = new TextColumn<Data>() {
public String getValue(Data object) {
return object.getValue(columnName); // this line doesn't even compile because columnName isn't visible here
}
};
table.addColumn(column, columnName);
}
RootPanel.get("GwtCellTableContainerDiv").add(table);
}
you need to build your second GWT App (the one having the custom CellTable) with the Cross Site Linker. With this linker GWT produces javascript that can be used in other javascript applications. ( http://code.google.com/intl/de-DE/webtoolkit/doc/latest/DevGuideOrganizingProjects.html#DevGuideModuleXml The section about Linkers)
To communicate with the CellTable App it has to export some Javascript functions with JSNI to be callable from javascript, here is an example: http://code.google.com/intl/de-DE/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html#calling