org.apache.click.util
Annotation Type Bindable


@Target(value=FIELD)
@Retention(value=RUNTIME)
public @interface Bindable

Provides a Page field auto binding annotation. Please see the user guide sections on Autobinding and Autobinding Using Annotations for a detailed description of Page field binding.

Bindable can bind private, protected and public Page fields.

Note if a @Bindable field's visibility is not public then Click will set the field to be accessible using reflection. If the Java application server has restricted security policies in place then this may cause a SecurityException to be thrown. In these environments you can either modify your fields visibility to be public or modify your servers Java security policy.

Configuration

By default "autobinding" will bind both public page fields and fields annotated with the @Bindable annotations. If you do not want "public" fields to be bindable you can set the autobinding attribute to "annotation" in your click.xml config file:
 <click-app>
   <pages package="com.mycorp.page" autobinding="annotation"/>
 </click-app> 

Bindable Example

Below is an example using of page fields annotated with the @Bindable annotation:
 public class BindableDemo extends Page {

     // ActionLink automatically added to Page control list
     @Bindable protected ActionLink link = new ActionLink();

     // Message string is automatically added to Page model
     @Bindable protected String message;

     public BindableDemo() {

         // Listener method invoked when link clicked
         link.setActionListener(new ActionListener() {
             public boolean onAction(Control source) {
                 // message added to page mode and rendered in template
                 message = "I was clicked";
                 return true;
             }
         });
     }

 }