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.util.logging.*; 014 015import fc.jdbc.*; 016import fc.io.*; 017import fc.util.*; 018 019/** 020Represents a grouped set of radio buttons 021 022@author hursh jain 023**/ 024public class RadioGroup extends ChoiceGroup 025{ 026/** {@inheritDoc} **/ 027public RadioGroup(String name) 028 { 029 super(name); 030 } 031 032public Field.Type getType() { 033 //no separate radiogroup since no such thing in HTML 034 //radiogroups = radio's with same name 035 return Field.Type.RADIO; 036 } 037 038/** 039Convenience method that returns the selected option as a 040String. 041<p> 042If there is no selection, returns <tt>null</tt> 043**/ 044public String getStringValue(FormData fd) 045 { 046 if ( ! isFilled(fd) ) 047 return null; 048 049 ChoiceGroup.Data data = (ChoiceGroup.Data) fd.getData(name); 050 Iterator it = data.selectedMap.values().iterator(); 051 return ( ((Choice)it.next()).getValue() ); 052 } 053 054/** 055Convenience method that returns the value of this 056field as a integer. 057 058@throws NumberFormatException if the value could not be 059 returned as in integer. 060*/ 061public int getIntValue(FormData fd) 062 { 063 return Integer.parseInt(getStringValue(fd)); 064 } 065 066/** 067Convenience method that returns the value of this 068field as a boolean. 069*/ 070public boolean getBooleanValue(FormData fd) { 071 return Boolean.valueOf(getStringValue(fd)).booleanValue(); 072 } 073 074}