16.02.2015 Views

Step by step tutorial: how to build a bean for Servoy - Servoy Stuff

Step by step tutorial: how to build a bean for Servoy - Servoy Stuff

Step by step tutorial: how to build a bean for Servoy - Servoy Stuff

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

How <strong>to</strong> <strong>build</strong> a <strong>bean</strong> <strong>for</strong> <strong>Servoy</strong> - A <strong>step</strong> <strong>by</strong> <strong>step</strong> <strong>tu<strong>to</strong>rial</strong> brought <strong>to</strong> you <strong>by</strong> <strong>Servoy</strong> <strong>Stuff</strong><br />

X. Adding some Ajax behavior<br />

One last thing we need <strong>to</strong> take care of in the Wicket <strong>bean</strong> is <strong>to</strong> make sure that our component triggers<br />

Ajax callback <strong>to</strong> <strong>Servoy</strong> whenever our value changes. Remember that we did it with an ActionListener<br />

and a FocusAdapter anonymous inner class in our Swing <strong>bean</strong>.<br />

Well, here we are going <strong>to</strong> code the equivalent in Wicket.<br />

Wicket doesn’t know about java.awt listeners, but it relies heavily on “Behaviors”, basically a Behavior<br />

is some code that will generate some JavaScript on the client side. There are regular behaviors but<br />

there are also AjaxBehaviors, and the one we will use is the well named<br />

“AjaxFormComponentUpdatingBehavior”<br />

(org.apache.wicket.ajax.<strong>for</strong>m.AjaxFormComponentUpdatingBehavior <strong>to</strong> be precise).<br />

We could create an anonymous inner class here, but since this is an important class and we might<br />

need <strong>to</strong> add some code later, we will create a proper java file <strong>for</strong> it. Let’s add a new class<br />

“TextChangesUpdatingBehavior” <strong>to</strong> our “net.stuff.servoy.<strong>bean</strong>s.test.wicket” package:<br />

24/37

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!