/*
 * HtmlForm.java
 *
 * Created on October 25, 2000, 6:44 PM
 */

package ovt.servlet;

import java.beans.*;
import java.util.*;

/**
 *
 * @author  ko
 * @version 
 */
public class HtmlForm extends Object {
    
    protected Vector components = new Vector();
    
    protected String action;
    /** Holds value of property name. */
    protected String name = "";
    /** Creates new HtmlForm */
    public HtmlForm(String action) {
        this.action = action;
    }
    
    public HtmlForm(String action, String name) {
        this.action = action;
        this.name = name;
    }
    
    public void add(HtmlPropertyEditor ed) {
        components.addElement(ed);
    }
    
    public String toString() {
        String res = "<FORM NAME=\""+ getName() +"\" ACTION=\""+ getAction() +
        "\" METHOD=\"POST\">";
        Enumeration e = components.elements();
        HtmlPropertyEditor ed;
        while (e.hasMoreElements()) {
            ed = (HtmlPropertyEditor)e.nextElement();
            res += ed.toString();
        }
        // close the tag
        res+="</FORM>";
        return res;
    }

    /** Getter for property name.
     * @return Value of property name.
     */
    public String getName() {
        // set some unique name if no is provided
        if (name.equals("")) name = "form" + Math.abs(new Random().nextInt());
        return name;
    }
    /** Setter for property name.
     * @param name New value of property name.
     */
    public void setName(String name) {
        this.name = name;
    }
    
    public String getAction() {
        return action;
    }
}