001// Copyright (c) 2001 Hursh Jain (http://www.mollypages.org) 
002// The Molly framework is freely distributable under the terms of an
003// MIT-style license. For details, see the molly pages web site at:
004// http://www.mollypages.org/. Use, modify, have fun !
005
006package fc.web.forms;
007
008import javax.servlet.*;
009import javax.servlet.http.*;
010import java.io.*;
011import java.util.*;
012import java.util.regex.*;
013import java.sql.*;
014
015/**
016Refreshes the value of a field (or fields) before the field is displayed
017to the user. Refreshed values are typically retrieved from a database.
018*/
019public abstract class FieldRefresher
020{
021Field field;  //set by target field when added to it
022
023/**
024Refresh the value of the field. The new values are request specific (and
025each HTTP request handler thread will update the values for that request
026independent of other requests). The values should be stored in the
027supplied form data object by invoking field methods that look like:
028<tt>setValue(<i>FormData fd</i>,....)</tt>.
029<p>
030It is possible for the specified form data to be <tt>null</tt>. 
031
032@param  fd    the form data object, possibly <tt>null</tt> if there
033        is no submit data.
034*/
035public abstract void refresh(FormData fd) throws IOException, SQLException;
036
037/**
038There must be a way to figure out if the client hacked/delete/modified the
039form before submitting it. Since the rendered values are different per
040request, we cannot rely on values that the target field was constructed
041with. This method is conceptually similar to a {@link
042Dependency#isSubmitDataValid} method.
043
044This method can be implemented to check the submitted values and return
045<tt>true</tt> if the submit was valid, <tt>false</tt> otherwise.
046<p>
047The default implementation always returns <tt>true</tt>. 
048*/
049public boolean isSubmitValid(FormData fd) { 
050  return true;
051  }
052
053public String toString() {
054  return "[Refresher: " + field.name + "]";
055  }
056}