Monday, June 25, 2012

Obtaining hostname and printers via applet

In this post I'm going to show how to obtain client's hostname, printers and display them in the page.



At first let's create new generic application with generic project called ViewController:


In the project create new JSP page called container:


Then create taskflow called main and drop it into the container page as region (pay attention to panelStretchLayout in the af:form tag):


Create page fragment called start in directory fragments with big button "Get hostname and buttons" in the center of the fragment and add it as default activity to the taskflow main:

with code:

In order to make JDeveloper aware of the Trinidad components you should add to the project jsp tag library "Trinidad HTML components":
Now let's create fragment which will do all work with applet
and add it to the taskflow
set action for button in start.jsff:
change the appletSplashForm page code:

create file with javascript event handler for af:clientListener declared in the page:
with code:

create backing bean AppletBean with method to handle events from javascript method:



with code:
To parse JSON array I use org.json code which available here. You should download it and put in the src folder in the ViewController:

Now let's create page fragment which will display results:

add it to taskflow

and set code

Time to create applet in new generic project Applet:
create class HostPrinters in package com.hostnameandprinter.applet with code:

jdeveloper will say he doesn't know about JSObject. To deal with it you should add to project library plugin.jar. In windows it can be found here: 

To build it as jar file we should create deployment profile with archive type Jar File and call it HostNameApplet. Other options leave default:

Deploy project:


Now we should sign jar file and add it to ViewController project:
And finally decorate splash form. Create css file HostNameAndPrinters.css in css folder:


code:

and create file trinidad-skins.xml in WEB-INF directory with code:

modify trinidad-config.xml file.
It should be like this:
Now let's run page container.jspx. We'll see a page with a big button in the center:
 click it:
  and results:
Oopps... Right caption for big button is "Get hostname and printers". =) You can download application here.

3 comments:

  1. Thanks for great article. I would like to test your application, but download link is not valid. Can you upload it again?

    Kind regards

    ReplyDelete
  2. Hi. Unfortunately I can't find it on my computers. =(
    Moreover this post is outdated because of NPAPI and applets technology. They are deprecated and will be removed in future. https://blogs.oracle.com/java-platform-group/entry/moving_to_a_plugin_free

    Apparently you should use JNLP to launch java code on the client hosts and use Ajax to comunicate with it. I'm going to write a post about implementing Java Web Start application with functionality of applet described in this post.

    ReplyDelete
  3. Thanks for the reply. I will look into that and continue to follow your blog.

    ReplyDelete