In order to access private fields, you need to get them from the class's declared fields and then make them accessible:
Field f = obj.getClass().getDeclaredField("stuffIWant"); //NoSuchFieldException
f.setAccessible(true);
Hashtable iWantThis = (Hashtable) f.get(obj); //IllegalAccessException
EDIT: as has been commented by aperkins, both accessing the field, setting it as accessible and retrieving the value can throw Exception
s, although the only checked exceptions you need to be mindful of are commented above.
The NoSuchFieldException
would be thrown if you asked for a field by a name which did not correspond to a declared field.
obj.getClass().getDeclaredField("misspelled"); //will throw NoSuchFieldException
The IllegalAccessException
would be thrown if the field was not accessible (for example, if it is private and has not been made accessible via missing out the f.setAccessible(true)
line.
The RuntimeException
s which may be thrown are either SecurityException
s (if the JVM's SecurityManager
will not allow you to change a field's accessibility), or IllegalArgumentException
s, if you try and access the field on an object not of the field's class's type:
f.get("BOB"); //will throw IllegalArgumentException, as String is of the wrong type
The other 3 are:
Control: Binds the DataForm(or View)WebPArt to a control somewhere on the page using the following syntax:
<ParameterBinding Name="Meal" Location="Control(clStartDate)" DefaultValue="01-01-2010"/>
or
<ParameterBinding Name="StartDate" Location="Control(clStartDate, SelectedValue)" DefaultValue="01-01-2010"/>
Where clStartDate is an ASP.NET Calender Control.
You see that Control()
takes either 1 or 2 parameters, the second is the name of the property on the control you want to use (i.e. 'Text' or 'SelectedIndex' etc etc.).
If you leave it empty (like in option 1) it will use the Control's DefaultProperty (as defined by the control itself).
As for the Form option, I've never used it before but I'm guessing it can be used to bind to a value received through a Form POST action.
More info can be found here
Best Answer
Same as you would a non-custom field type:
Only you cast to your custom field type.