fc.web.forms
Class TestDependency

java.lang.Object
  extended by fc.web.forms.TestDependency
All Implemented Interfaces:
Dependency

public class TestDependency
extends Object
implements Dependency

A test dependency implementation.


Constructor Summary
TestDependency(Select country, DependentSelect state)
           
 
Method Summary
 Object getInitialValues(Field f)
          Returns the initial values for the target field These are the values that are displayed when the form is first rendered.
 boolean isSubmitDataValid(FormData fd)
          Returns true if the submitted values are in a valid range of values.
 void renderDependencyData(FormData fd, Writer out)
          Writes out data to keep track of dependency state.
 void setDependencyDataFromSubmit(FormData fd, javax.servlet.http.HttpServletRequest req)
          The inverse of renderDependencyData, sets any depedency data submitted as part of the form.
 String toString()
           
 void updateValues(FormData fd, javax.servlet.http.HttpServletRequest req)
          Sets new values for target field in the FormData object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TestDependency

public TestDependency(Select country,
                      DependentSelect state)
Method Detail

getInitialValues

public Object getInitialValues(Field f)
Description copied from interface: Dependency
Returns the initial values for the target field These are the values that are displayed when the form is first rendered. The returned object is of a type that is suitable for the data of the target field. (typically an instance of a static inner data class of that field).

If there is no initial data, the returned object can also be null or an empty data object, depending on what the target field expects when there is no data.

Specified by:
getInitialValues in interface Dependency

updateValues

public void updateValues(FormData fd,
                         javax.servlet.http.HttpServletRequest req)
                  throws DependencyException
Description copied from interface: Dependency
Sets new values for target field in the FormData object. The target field then uses those values to render itself to the client. The data should be saved in FormData with the field name as the key.

Note:This method must invoke FormData.setDependencyUpdated() if it sets new values in the formdata object. New values are values that are different from the values that were last displayed to the client.

There are 2 conditions that typically must be satisfied for this to be true:

  1. Source not null: The source fields must have some data. For example, a country popup needs to be selected to some country value before the target dependent field (a state popup) can be populated. If no country is selected, we cannot calculate a dependent state value.
  2. Source changed: The source fields must have different data than the last time the form was rendered (which means that the client made a different selection/choice). For example, previously, the source field could have been 'usa'. The client then either changes that to 'uk' or leaves it alone. The last_value (which is rendered as a hidden field in the form) in conjunction with the submittd value of the source field(s) can be used to figure out if there was a dependency change. If the source value is 'usa' and the last_value is 'usa', then we know there is no need for any dependency updates (since the usa values are already shown to the user).

Specified by:
updateValues in interface Dependency
Throws:
DependencyException

setDependencyDataFromSubmit

public void setDependencyDataFromSubmit(FormData fd,
                                        javax.servlet.http.HttpServletRequest req)
Description copied from interface: Dependency
The inverse of renderDependencyData, sets any depedency data submitted as part of the form. This data is set in the specified FormData object and can be later used by the updateValues method.

Specified by:
setDependencyDataFromSubmit in interface Dependency

renderDependencyData

public void renderDependencyData(FormData fd,
                                 Writer out)
                          throws SQLException,
                                 IOException
Description copied from interface: Dependency
Writes out data to keep track of dependency state. This data is typically the last selected values of some source field (say last selected source country for a target dependent state field) and usually written out as a hidden field in the form.

Specified by:
renderDependencyData in interface Dependency
Throws:
SQLException
IOException

isSubmitDataValid

public boolean isSubmitDataValid(FormData fd)
Description copied from interface: Dependency
Returns true if the submitted values are in a valid range of values. For ultra-secure applications, the validity can be computed every time by recomputing/retrieving the dependent data and of-course, database constraints should always be employed.

If this method is not applicable, this method should return true every time.

Specified by:
isSubmitDataValid in interface Dependency

toString

public String toString()
Overrides:
toString in class Object