Java Expert

...because java matters

  • Increase font size
  • Default font size
  • Decrease font size

From MS Access Forms to jQuery Dialogs

E-mail Print PDF

Creating a framework to convert MS Access Forms to jQuery dialogs.

msaccess forms

jquery dialogs

A bit of API so far:

createDialog("nodedetails", 780, "Node Details"); 

This creates a jQuery Dialog, and loads the forms/nodedetails.html.

 

openDialog("nodedetails", { "hostname" : data.hostname });

This loads the values to populate 'nodedetails.html', using 'hostname' as parameter, and then opens the dialog. The HTML input name attribute can be bound to a database column.

 

A side by side comparison:

This is a work in progress, I'll update this from time to time.

Last Updated on Monday, 24 September 2012 17:04
 

Wicket Primer

E-mail Print PDF

Let's create a Movie site (if you haven't installed wicket yet, try http://wicket.apache.org/start/quickstart.html).

HomePage.html:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:wicket="http://wicket.apache.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>MovieDB</title>
</head>
<body>
<h1>MovieDB Homepage</h1>
</body>
</html>

HomePage.java:

package com.mycompany.moviedb;
import org.apache.wicket.markup.html.WebPage; public class HomePage extends WebPage { public HomePage() { } }

This initial version of the application consists of only one web page and there is no dynamic content in that page. In Wicket, we have to write two files for every page in the application: one is an HTML file that contains the template of the page, and the other is a Java source file containing the components that control the dynamic elements in the template. The name of the class (and therefore the base name of the Java source file) has to be the same as the base name of the HTML template file, as in HomePage.java and HomePage.html. Since, in our first example, there is no dynamic element in the template, there is no need for the class to supply any information to the template.

Last Updated on Wednesday, 11 January 2012 14:34
 

XQuery Primer

E-mail Print PDF

XQuery was devised primarily as a query language for data stored in XML form. So its main role is to get information out of XML databases.

Here's an XQuery that simply retrieves and displays the whole document:

doc('http://www.stylusstudio.com/examples/videos.xml')

The file contains a number of sections. One of them is an <actors> element, which we can select like this:

.//actors

This produces the result:

<actors>
<actor id="00000015">Anderson, Jeff</actor>
<actor id="00000030">Bishop, Kevin</actor>
<actor id="0000000f">Bonet, Lisa</actor>
...etc...
</actors>

A little more complex:

.//actors/actor[ends-with(., 'Lisa')]

gives the output:

<actor id="0000000f">Bonet, Lisa</actor>
<actor id="0000001b">Spoonhauer, Lisa</actor>

This XPath expression has two parts: a path .//actors/actor that indicates which elements we are interested in, and a predicate [endswith(., 'Lisa')] that indicates a test that the nodes must satisfy.

Let's suppose we want to find the titles of all the videos featuring an actor whose first name is Lisa:

//video[actorRef=//actors/actor[ends-with(., 'Lisa')]/@id]/title

XQuery FLWOR Expressions

XQuery allows you to write join queries in a similar way to the familiar SQL approach. Its equivalent of SQL's SELECT expression is called the FLWOR expression, named after its five clauses: for, let, where, order by, return.

Here's the previous example, rewritten this time as a FLWOR expression (and ordered by release date):

let $doc := .
for $v in $doc//video,
$a in $doc//actors/actor
where ends-with($a, 'Lisa')
and $v/actorRef = $a/@id
order by $v/year
return $v/title

If you've got a real database, the form of the queries won't need to change all that much from these examples. Instead of using the doc() function (or simply ".") to select a document, you're likely to call the collection() function to open a database, or a specific collection of documents within a database.

Examples by Michael Kay/Stylusstudio.

Last Updated on Thursday, 01 December 2011 12:54
 

XSLT 2.0/XPath 2.0 Primer

E-mail Print PDF

This primer is based on Michael Kay's "XSLT 2.0 and XPath 2.0, Programmer's Reference, 4th Edition". Some software engineering experience is assumed, otherwise you might need to brush up on XML and/or regular expressions. I will not go into how things were done with XSLT 1, I leave that for the masochists out there :)

So what is this all about? An XSLT processor parses a source document into a source tree, then applies a stylesheet to perform (complex) manipulations on the tree nodes, and produces a result document by serializing the result tree. To select the data (nodes) to be processed, XPath expressions are used.

Let's start with this: Once a value has been given to a variable, it cannot be changed! No big thing for all you 'functional programming' adepts, but everyone else will have to get used to a lot of recursion. Without assignment statements, we can do things in any order, because the result of one statement can no longer depend on what state the system was left in by the previous statement.

Before we dive in, we need to know a little about the seven kinds of nodes in the tree.

-Document		: One for each document, no parent, always the root of a tree.
-Element		: A part bounded by start and end tags, or empty such as <TAG/>.
-Text			: A sequence of consecutive characters.
-Attribute		: The name and value of an attribute written within an element start tag (except namespaces).
-Comment		: A comment written between <!-- and -->
-Processing instruction	: An instruction written between <? and ?> 
-Namespace		: A namespace declaration

 

Last Updated on Thursday, 08 December 2011 14:52