clickme.war

This demo show how to handle and process events on elements. Box.java contains code of catching and processing OnClick event.


clickme

In order to listen browser event you have only to annotated the processing method with event listener. In this example it is @OnClick listener in Box class.


/*
 * Add click event listener.
 */
@OnClick
public void click() {
	Length top = randomPos(getStyle(Top.class).getLength());
	Length left = randomPos(getStyle(Left.class).getLength());
	setPos(top, left);
}

When event is fired up on browser, the FireWeb engine transport event data to server. The server events processor calls annotated method on all listeners attached to that event at target element.


In App.java you can see how to add element to view by calling add method,


/*
 * Add clicked box to view
 */
add(new Box());

and page header elements as files with CSS.


/*
 * Attach style sheet file to page
 */
@Application(jarStyles = "org/fireweb/demo/clickme/clickme.css")
public class App extends FireWebApplication {

In the same way you can add: inline scripts, scripts in file, inline styles and other page header elements such as: <link>, <meta>, <script> and <style>.


The demo also shows how to mix CSS form file and inline styles of the element (Box.java).


/**
 * Set current box position.
 * 
 * @param top
 *            offset
 * @param left
 *            offset
 */
public void setPos(Length top, Length left) {
	setStyle(new Top(top)).setStyle(new Left(left));
	setText((int) left.getValue() + "," + (int) top.getValue());
}

Demo code you can get from here clickme.war