Seam component events

A very powerful feature in Seam that usually doesn’t get enough attention in my opinion is component-driven events. Seam component can raise or throw arbitrary event and any number of other Seam components can observe or listen to these events. This truly creates a loose coupled architecture. Components raise events and anyone who cares listens to the event. The components are not connected to each other in any way.

Let’s start with CourseManager component:

@Name("courseManager")
public class CourseManager {
 
   private String name; // setter and getter
 
   @Out(required=false)
   private String studentName;
 
   @Logger Log log;
 
   @RaiseEvent("courseDropped")
   public void drop() {
     studentName = name;
     log.info("course dropped");
   }
}

In component above when drop() method is invoked, courseDropped event will be raised via @RaiseEvent annotation. Once invocation is done, the component will outject studentName variable.

Although data can passed with the event, a better way is to use bijection in Seam. The name variable would most likely be submitted from a JSF page. Its value is assigned to studentName component variable and studentName is outjected after the method invokation. Anyone who is interested in this event can listen to it and also get the data associated with the event (via injection).
Read more »

Hibernate Validator with JavaFX

One of the key features in Exadel Flamingo is that it allows you to use Hibernate Validator based validation on JavaFX UI side.

On the server you can have something like this:

@Entity
@Name ("message")
public class Message {
   @Id @GeneratedValue
   private Long id;
 
   @Length(min=3, max=40)
   private String text;
   ...
}

This is a simple entity and also a Seam component.

On the JavaFX side all you need to do is this:

var textBox : TextBox = TextBox {};
var errorText: String {};
...
errorText = FlamingoServiceFactory.getHessianEntityValidator().
                    validate("message.text", textBox.text);

message.text – message is Seam component name and text is component property. textBox.text is JavaFX node (widget) whose value we need to validate.

Simple… right?

Calling Seam component from JavaFX

To use JavaFX in enterprise, you need to be able to connect JavaFX to enterprise backend such as Java EE, Seam or Spring. Here is an example how to call Seam component from JavaFX using Exadel Flamingo.

Seam component (server side)

@Name("messageManager")
public class MessageManager {
 
   public String callMe () {
        return "Seam component says: what's up"?;
}

JavaFX (client side)

public interface MessageManager {
   public String callMe ();
}
public class AppServiceFactory {
   public static MessageManager getMessageManager() {
	return (MessageManager) ServiceFactory.getService(MessageManager.class,
		"messageManager");
   }
}

JavaFX script:

var reply : String;
function call(): Void { 
     ...
     reply = AppServiceFactory.getMessageManager().callMe(); 
     ...
}

That’s it. Simple, easy and transparent. Seam is used the same way if you were building a JSF-based application.

Enterprise JavaFX: Our Experience Building a JavaFX UI for a Seam Booking Application

This article is also posted on JavaLobby.com

This is a guest post by Anton Polyakov. Anton is Senior Developer at Exadel, he describes our experience building a JavaFX front end for a Seam booking application.

JavaFX is new tool set for developing and delivering Rich Internet Applications or RIAs. JavaFX 1.0 was released in December 2008, and JavaFX 1.2 was released in June 2009. As these new releases have rolled out, the JavaFX community has been growing fast. This growth has produced a large selection of resources, articles, blog posts, books, and extension projects.

Over this time, while JavaFX has been used extensively to provide “richness� in applications, it has been mostly “missing in action� for enterprise-level Web applications that would involve greater integration of JavaFX with the server side of the application. Remember, a Rich Internet Application is delivered from a server to the the client, but, more importantly, it continues to communicate with the server. The UI runs on the client while the application logic runs on the server.

We believe that for JavaFX to continue growing and compete against Flex and Silverlight, it should be acceptable by the enterprise for use in applications that take full advantage of both sides of Rich Internet Applications (Rich Enterprise Applications). Adobe and its community has done an excellent job demonstrating that Flex can be used to build real-world enterprise applications. The same needs to happen for JavaFX.

Exadel’s Experience with JavaFX

Exadel has been working with JavaFX for more than a year now. In June of 2008, we took the popular Jboss Seam hotel booking Web application and built a JavaFX UI on it as a replacement for the standard JSF UI. Back then, we used a prerelease version of JavaFX. (There was very little interest in JavaFX at that time.)

Fast forward to today. We took the same Seam booking application and updated the JavaFX UI to JavaFX 1.2. You can find the demo running here. For your local use, you can also download the file to run or a Maven project to build this application.

Redoing the Booking Application

What we are going to do in the rest of this article is share our experience building this demo as an example of building an enterprise JavaFX applications. The task wasn’t easy (but then it wouldn’t have been as fun).

Read more »

Enterprise JavaFX – Seam booking demo application

You can now view or download and deploy one of the first real enterprise JavaFX application. We took the popular Seam booking demo application and created JavaFX UI for it. The JavaFX side is connected to Seam via Flamingo RIA framework.

screenshot_001

View online
You can view and run the application by going to this URL: http://demo.flamingo.exadel.com/booking/. You will also see JSF/RichFaces and Flex versions of the application. All instances are connected to the same Seam back-end. Once you register, you can use the same name/password information to login using any other user interface.

Download and run
You can also download, deploy and run this application on your machine. There are two ways you can do it:

  1. Deploy (ready) booking.ear file
  2. Build the application with Maven and deploy it

Download the source and application (.ear). You will find instructions on how to deploy and build inside the zip file.

We are working on an article to tell you about our experience building an enterprise application with JavaFX. Lastly, yesterday we released new version of our JavaFX Studio plug-in for Eclipse. Get it here.

Have fun with JavaFX!

Enterprise JavaFX – complete edition

The following series shows how to connect JavaFX to enterprise server-side technologies. This series covers Seam.

A future series will cover how to connect JavaFX with Spring framework.

JavaFX applet connected to JBoss Seam – screen shot

This is JavaFX applet talking to JBoss Seam on the server. The integration is done via Exadel Flamingo.

Validation is done via Hibernate Validation.

Excellent articles on using RichFaces/Seam, RichFaces/Spring and Hibernate

User registration solution using JBoss Seam with JSF / RichFaces and Hibernate
User authentication / registration with JSF / RichFaces, Spring, and Hibernate

Thanks to thelabdude for providing these excellent tutorials.

JavaFX with JBoss Seam

This is an introductory post that shows how to use JavaFX with JBoss Seam. Communication between JavaFX and server (Seam) is done via Flamingo RIA framework. Flamingo, not only provides Flex to server communications like Granite DS and Blaze DS, but also provides JavaFX to server communications.

screenshot01.png

JavaFX:

package com.exadel.flamingo.javafx;
 
 
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.TextOrigin;
import javafx.ext.swing.SwingButton;
import javafx.scene.layout.VBox;
import javafx.scene.control.TextBox;
 
import com.exadel.flamingo.javafx.samples.helloworld.javafx.HelloworldClient;
 
class Hello {
    public var name:String;
    public var str:String;
}
var helloModel = new Hello();
 
HelloworldClient.setServerUrl(FX.getArgument('uri') as java.lang.String);
 
var helloText: TextBox = TextBox {
    text: bind helloModel.name with inverse
    columns: 7
    selectOnFocus:true
}
 
var helloLabel = Text{
    y:8
    font: Font { name:"sansserif", size: 12 }
    fill: Color.BLACK
    content: bind "Server says: {helloModel.str}"
    textOrigin: TextOrigin.TOP
}
 
var helloButton = SwingButton  {
    text:"Say Hello!"
    action: function(){
        helloModel.str = HelloworldClient.CLIENT.hello(helloModel.name);
    }
}
 
Stage {
    title: "Helloworld Sample"
    width: 200
    height: 150
    scene: Scene {
        content: VBox {
            translateX: 5
            translateY: 5
            spacing: 10
            content: [                
                HBox {
                    content: helloText
                    spacing: 10
                },
                HBox {
                    content: helloButton
                    spacing: 10
            	},
                HBox {
                    content: helloLabel
                    spacing: 10
            }]
 
        }
    }
}

HelloAction interface:

package com.exadel.flamingo.javafx.samples;
 
import org.jboss.seam.annotations.remoting.WebRemote;
 
public interface IHelloAction {
 
    @WebRemote
    public String hello(String name);
}

HelloAction (Seam component):

package com.exadel.flamingo.javafx.samples;
 
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.remoting.WebRemote;
 
@Scope(ScopeType.STATELESS)
@Name("helloAction")
public class HelloAction implements IHelloAction {
 
    @WebRemote 
    public String hello(String name) {
        return "Hello, " + name;
    }
}

Helloworld client:

package com.exadel.flamingo.javafx.samples.javafx;
 
import com.caucho.hessian.client.HessianProxyFactory;
import com.exadel.flamingo.javafx.samples.IHelloAction;
import java.net.MalformedURLException;
 
public class HelloworldClient {
 
    public static HelloworldClient CLIENT;    
    private IHelloAction _service;    
    private String _url;
 
    private HelloworldClient(String string) {
        _url = string;
    }
    public static void setServerUrl(String url) {
        CLIENT = new HelloworldClient(url);
    }
    private IHelloAction getService() {
        if (_service == null) {
            try {
                HessianProxyFactory factory = new HessianProxyFactory();
                _service = (IHelloAction) factory.create(IHelloAction.class, _url);
            } catch (MalformedURLException ex) {
                System.out.println(ex);
            }
        }
        return _service;
    }
    public String hello(String s) {
        return getService().hello(s);
    }
}

JSP file:

<%
String uri = request.getScheme() + "://" + 
request.getServerName() + ":" +
request.getServerPort() + 
request.getContextPath();
%>
 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Helloworld</title>
</head>
<body>
<h2>JavaFX with Seam!</h2>   
	<script src="http://dl.javafx.com/1.1/dtfx.js"></script>
	<script>
	    javafx(
	        {
	              archive: "jnlp/helloworld-client-javafx.jar",
	              draggable: true,
	              width: 600,
	              height: 560,
	              code: "com.exadel.flamingo.javafx.MainFrame",
	              name: "Helloworld",
		      	uri:'<%= uri + "/seam/resource/hessian/helloAction" %>'
	        }
	    );
	</script>
</body>
</html>

Updating training materials

Started to update my training materials for JSF and RichFaces and shortly Seam. Right now I have slides, going to convert them to a short training booklet. Why am I doing this? Well, I have realized that training is not a presentation, so slides is not the best way to do it. Plus, it’s going to save lots of paper. I used to print 2-slides per page and all the space around them wasted. The short booklet will also allow to include more details and examples.

Next Page »