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