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.*; 012 013import fc.jdbc.*; 014import fc.io.*; 015import fc.util.*; 016 017/** 018Keeps track of a set of related/grouped fields in a form. 019<p> 020A fieldref is is useful when a set of fields are created 021programmatically from a database table and need to be 022retrieved from the form (but we don't know the names of 023those fields since they were created dynamically -- however, 024those fields can be added both to the form and to a 025fieldref and obtained via then the name of the fieldref 026(whose name we <b>do</b> know.) 027<p> 028<b>Note</b>: Any fields contained in this object must also 029be added directly to the form. 030 031@author hursh jain 032**/ 033public final class FieldRef 034{ 035String name; 036Object obj; 037 038/** 039Creates a new field with the specified name. All fieldref's 040in a particular form must have a unique name. 041**/ 042public FieldRef(String name) 043 { 044 this.name = name; 045 } 046 047/** 048Creates a new field with the specified name and the 049specified object (which may be any data structure like a 050list, map or whatever containing references to fields in 051the form). 052**/ 053public FieldRef(String name, Object obj) 054 { 055 this.name = name; 056 this.obj = obj; 057 } 058 059 060/** 061Adds an object to this fieldref. The object will typically 062be some datastructure that contains references to fields 063in the form. 064*/ 065public void add(Object obj) 066 { 067 this.obj = obj; 068 } 069 070/** 071Returns the data object contained in this fieldref as a List. 072*/ 073public List getList() { 074 return (List) obj; 075 } 076 077 078/** 079Returns the data object contained in this fieldref as a Map. 080*/ 081public Map getMap() { 082 return (Map) obj; 083 } 084 085/** 086Returns the data object contained in this fieldref. 087*/ 088public Object getObject() 089 { 090 return obj; 091 } 092 093String getName() { 094 return name; 095 } 096 097public String toString() { 098 StringBuffer buf = new StringBuffer(); 099 buf.append("FieldRef: ").append(name); 100 buf.append("; Contains: \n"); 101 buf.append(obj); 102 return buf.toString(); 103 } 104 105} //~class Text