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.util.logging.*;
014    
015    import fc.jdbc.*;
016    import fc.io.*;
017    import fc.util.*;
018    
019    /** 
020    Represents a grouped set of radio buttons
021    
022    @author hursh jain
023    **/
024    public class RadioGroup extends ChoiceGroup
025    {
026    /** {@inheritDoc} **/
027    public RadioGroup(String name)
028      {
029      super(name);
030      }
031      
032    public 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    /** 
039    Convenience method that returns the selected option as a
040    String. 
041    <p>
042    If there is no selection, returns <tt>null</tt>
043    **/
044    public 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    /**
055    Convenience method that returns the value of this 
056    field as a integer.
057    
058    @throws NumberFormatException if the value could not be
059                    returned as in integer. 
060    */
061    public int getIntValue(FormData fd) 
062      {
063      return Integer.parseInt(getStringValue(fd));
064      }
065    
066    /**
067    Convenience method that returns the value of this 
068    field as a boolean. 
069    */
070    public boolean getBooleanValue(FormData fd) {
071      return Boolean.valueOf(getStringValue(fd)).booleanValue();
072      }
073    
074    }