What is form Binding

Form hold data which is submitted to trigger the action on server. In the conventional approach when form is submitted the posted data is retrieved at server side component by getting parameters, like


form.getParameter(“userName”)
form.getParameter(“userAge”)
form.getParameter(“userCity”)
…..

This requires a lot of plumbing code. to make it easier latest frameworks have come with a new concept called as “Binding”.
In Form binding you create an object(POJO) which is binded to the form. so whenever the form is submitted, the object gets populated automatically without writing any plumbing code.

Similarly the “Event Binding” happens. You can bind an event with the form,  register a listener to it and  when that particular even is fired, it invokes your action. A very beautiful implementation is implemented in GWT google web toolkit for the same.

The data can  be bind to form with events like refresh, buffering etc using the xml configurations or annotations.

Sample from a Binding File

To give you an idea of what a binding file looks like, below a very simple example is shown.

<fb:context xmlns:fb="http://apache.org/cocoon/forms/1.0#binding" path="/" >
    <fb:value id="firstname" path="firstName"/>
    <fb:value id="lastname" path="lastName"/>
    <fb:value id="email" path="email"/>
</fb:context>

With the dyna form in frame works like Struts 2.0 even the data object is created automatically via the xml configurations only. Hence it save time to write and maintain the data object class as well.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s