Thursday, January 23, 2014

HybridJava vs. Wicket

The promise of initial JSP was about interlaying (which means combining, not separating) HTML markup and Java within the presentation layer code. Respecting the boundary between the Presentation Layer and the Business Layer is a must, but note that the former has logic of its own too. The JSP way of doing things is in using Java to code presentation logic.

To understand Wicket, I got the book “Pro Wicket” by Karthik Gurumurthy. What does this specific technology provide to express the component structure of the application? The book tells “You can liken Wicket development to Swing development” and also “the component hierarchy is specified explicitly through Java code” (p 9). In other words it is done the way it was some 25 years ago with Visual Basic and all the rest desktop UI development tools. There is nothing bad in such an approach, but alas, that is a pre-HTML presentation technology. Technically it is about manually coding endless “new” and “add” operations. Reading further one finds out that the “component hierarchy” (structure) is simultaneously depicted in a form of markup. This duplication of information is a big step back even compared to the Visual Basic. See Listings 4.19 to 4.22 pages 129-130 – MyBorder is the most compact example I found. If you code the same example in HybridJava all will look indeed very similar … except that there will be NO listings 4.20 and 4.22 (repeated below) at all.

What is the need for MyBorder to be a component if it does have neither state nor behavior? A simple answer is that the Wicket framework has nothing of lighter weight than a component. HybridJava has. HybridJava approach is that presentation components (in that they have place in the hierarchy) are nothing different from HTML elements and thus markup is sufficient. A clever enough framework may (and HybridJava does) figure out all the rest behind the scenes. In particular HybridJava framework performs all necessary “new” and “add” operations and assigns dynamic IDs. 

More on IDs: page 216 states “This feature demonstrates Wicket’s excellent support for dynamic templates.” They probably meant to say that Tabbed Panel example (NOT a feature!) demonstrates something. What it demonstrates in reality is that the Wicket framework has completely failed to solve the dynamic IDs puzzle. This specific example works, but only because in the book’s own words “At any given point in time, only one Panel can be active or visible”. HybridJava has solved the dynamic IDs puzzle.

Another thing that the book shadows is the Wicket solution for loops. In the Wicket framework even a plain loop is a component, so the “Wicket way” of coding repetitions in presentation layer is (in ADDITION to markup!) something like:
Loop loop = new Loop( new LoopItem( … // Lisp is immortal !!!
HybridJava is not that “revolutionary” and sticks to using traditional Java “while” keyword.
// From “Pro Wicket” book, listings 4.20 and 4.22 (not needed in HybridJava!)
package com.apress.wicketbook.layout;
import wicket.markup.html.border.Border;
public class MyBorder extends Border {
public MyBorder(String id) {
package com.apress.wicketbook.layout;
import wicket.markup.html.WebPage;
import wicket.markup.html.basic.Label;
import wicket.markup.html.border.Border;
import wicket.model.Model;
public class MyPage extends WebPage {
public MyPage() {
Border border = new MyBorder("myborder");
border.add(new Label("label", new Model(" Wicket Rocks 8-) ")));

Wednesday, January 1, 2014

HybridJava Challenge

The HybridJava Challenge


Comparison of Web frameworks is a difficult task. Even if we limit ourselves to the Java world server-side presentation layer we find dozens of frameworks. But what is a good framework? A freshman student and a software company may have different criteria.


Let me introduce a small example of a dynamic page implemented using HybridJava framework. The challenge is for other frameworks (JSF, Spring, etc.) to implement the same page AND demonstrate same convenience, conciseness and performance.   


In HybridJava adding components to a page or to another component is as simple as inserting tags and requires no programming or configuration. So in our example we create a simple component that has a Submit button and counts the number of times the button was pushed. The framework supports server-side event propagation trough the component tree. We insert 12 such components into the page (file :





            <table border="3" cellpadding="5"> 

                <ForI n=3>            


                        <ForJ n=4>







    </EventLog>  // renders events from inner components      



The screenshot of this page:



And here is the component which is a pair of markup + Java class:




       <widget name=Component>

    <div align="center"><HJRadio checked=${!flag} verb="toggle" value="off"/>

        <HJRadio checked=flag verb="toggle" value="on"/></div>




package com.HybridJava.Challenge;

import com.HybridServerPages.BaseComponent;

public class Component_WS extends BaseComponent {

int count;

boolean flag = false; // current state

private boolean prev_flag = false;

@Override protected void $handleComponent(String h1,String h2){

    String value = $getParam("toggle",flag ? "on" : "off");


         flag = true;


         flag = false;

    if(flag != prev_flag){

        $send(2,"Flag " + flag, null);      


    prev_flag = flag;








As a matter of fact – file Challenge.war is 34 kilobytes.