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    
006    package fc.web.forms;
007    
008    import javax.servlet.*;
009    import javax.servlet.http.*;
010    import java.io.*;
011    import java.util.*;
012    import java.util.regex.*;
013    import java.sql.*;
014    
015    /**
016    Refreshes the value of a field (or fields) before the field is displayed
017    to the user. Refreshed values are typically retrieved from a database.
018    */
019    public abstract class FieldRefresher
020    {
021    Field field;  //set by target field when added to it
022    
023    /**
024    Refresh the value of the field. The new values are request specific (and
025    each HTTP request handler thread will update the values for that request
026    independent of other requests). The values should be stored in the
027    supplied form data object by invoking field methods that look like:
028    <tt>setValue(<i>FormData fd</i>,....)</tt>.
029    <p>
030    It 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    */
035    public abstract void refresh(FormData fd) throws IOException, SQLException;
036    
037    /**
038    There must be a way to figure out if the client hacked/delete/modified the
039    form before submitting it. Since the rendered values are different per
040    request, we cannot rely on values that the target field was constructed
041    with. This method is conceptually similar to a {@link
042    Dependency#isSubmitDataValid} method.
043    
044    This 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>
047    The default implementation always returns <tt>true</tt>. 
048    */
049    public boolean isSubmitValid(FormData fd) { 
050      return true;
051      }
052    
053    public String toString() {
054      return "[Refresher: " + field.name + "]";
055      }
056    }