1 16 package org.apache.myfaces.examples.listexample; 17 18 import javax.faces.context.FacesContext; 19 20 21 27 public class SimpleCountryForm 28 { 29 private long _id; 30 private String _name; 31 private String _isoCode; 32 33 public long getId() 34 { 35 return _id; 36 } 37 38 public void setId(long id) 39 { 40 _id = id; 41 if (_id > 0) 42 { 43 SimpleCountry simpleCountry = getList().getSimpleCountry(_id); 44 if (simpleCountry == null) 45 { 46 return; 47 } 48 _name = simpleCountry.getName(); 49 _isoCode = simpleCountry.getIsoCode(); 50 } 51 } 52 53 public void setIsoCode(String isoCode) 54 { 55 _isoCode = isoCode; 56 } 57 58 public String getIsoCode() 59 { 60 return _isoCode; 61 } 62 63 public String getName() 64 { 65 return _name; 66 } 67 68 public void setName(String name) 69 { 70 _name = name; 71 } 72 73 private SimpleCountry getSimpleCountry() 74 { 75 return new SimpleCountry(_id, _name, _isoCode, null, null); 76 } 77 78 public String save() 79 { 80 getList().saveSimpleCountry(getSimpleCountry()); 81 return "ok_next"; 82 } 83 84 public String delete() 85 { 86 getList().deleteSimpleCountry(getSimpleCountry()); 87 return "ok_next"; 88 } 89 90 public String apply() 91 { 92 getList().saveSimpleCountry(getSimpleCountry()); 93 return "ok"; 94 } 95 96 private SimpleCountryList getList() 97 { 98 Object obj = FacesContext.getCurrentInstance().getApplication().getVariableResolver() 99 .resolveVariable(FacesContext.getCurrentInstance(), "countryList"); 100 return (SimpleCountryList) obj; 101 102 } 103 } 104 | Popular Tags |