Custom CRUD annotations

henricpersson edited this page Feb 11, 2011 · 1 revision

If the standard CRUD annotations aren't enough, you can plug in your own handler.

There are two parts where you need to plug in: on the server side and on client side, through GWT code.

The below example plugs in a video field handler.

Server side

In your Configurator.init(), add your plugin implementation:

		PluginCrudManager.get().addCrudHandler(new PluginCrudHandler() {
			public CrudField process(Field f, Object entity) {
				if (!f.isAnnotationPresent(Video.class)) {
					return null;
				Long videoId;
				try {
					videoId = (Long) f.get(entity);
				} catch (Exception e) {
					throw new RuntimeException("Failed to get video id", e);
				return new VideoField(videoId);

Client side GWT

In your GWT entry point class, add a plugin to the CrudFieldResolver:

	public void onModuleLoad() {
		CrudFieldResolver.addPluginHandler(new CrudFieldPluginHandler() {
			public CrudInputField<?> process(CrudField field) {
				if (!(field instanceof VideoField)) {
					return null; //not my cup of tea
				VideoField vf = (VideoField) field;
				return new VideoInputField(vf);

The VideoField class in the above example is a serializable class that can be used on the server side and the GWT client side. Therefore it must be placed in a package that your GWT module is aware of. This class is used for the RPC communication between the server and the client.

This code will plug in the possibility to use a @Video annotation on Long fields.