// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package test.standard;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean
@RequestScoped
public class TestStandard {
    // form fields
    private Integer f1;
    private String f2;
    private String f3;
    public Integer getF1() {
        return f1;
    }
    public void setF1(Integer f1) {
        this.f1 = f1;
    }
    public String getF2() {
        return f2;
    }
    public void setF2(String f2) {
        this.f2 = f2;
    }
    public String getF3() {
        return f3;
    }
    public void setF3(String f3) {
        this.f3 = f3;
    }
    // form action
    public void save() {
    }
    // form options list
    public List<String> getOptions() {
        List<String> res = new ArrayList<String>();
        res.add("A");
        res.add("B");
        res.add("C");
        return res;
    }
    // data table
    public static class T1 {
        private int f1;
        private String f2;
        public T1() {
            this(0, "");
        }
        public T1(int f1, String f2) {
            this.f1 = f1;
            this.f2 = f2;
        }
        public int getF1() {
            return f1;
        }
        public void setF1(int f1) {
            this.f1 = f1;
        }
        public String getF2() {
            return f2;
        }
        public void setF2(String f2) {
            this.f2 = f2;
        }
    }
    public List<T1> getData() {
        List<T1> res = new ArrayList<T1>();
        res.add(new T1(1,"A"));
        res.add(new T1(2,"BB"));
        res.add(new T1(3,"CCC"));
        res.add(new T1(4,"DDDD"));
        res.add(new T1(5,"EEEEE"));
        return res;
    }
    // AJAX field
    private String s;
    public String getS() {
        return s;
    }
    public void setS(String s) {
        this.s = s;
    }
    /*
    // ensure session exist
    @PostConstruct
    void initialiseSession() {
        FacesContext.getCurrentInstance().getExternalContext().getSession(true);
    }
    */
}
