1 16 17 package org.apache.taglibs.standard.examples.taglib; 18 19 import java.io.IOException ; 20 21 import javax.servlet.jsp.*; 22 import javax.servlet.jsp.tagext.*; 23 import javax.servlet.jsp.jstl.core.*; 24 25 import org.apache.taglibs.standard.examples.beans.Customer; 26 27 33 public class CustomerFmtTag extends TagSupport { 34 35 38 39 private Customer customer; 40 41 42 private String fmt; 43 44 47 public CustomerFmtTag() { 48 super(); 49 init(); 50 } 51 52 private void init() { 53 customer = null; 54 fmt = null; 55 } 56 57 60 public int doStartTag() throws JspException { 61 JspWriter out = pageContext.getOut(); 62 try { 63 if (fmt.equalsIgnoreCase("short")) { 64 out.println(customer.getFirstName() + " " + 65 customer.getLastName()); 66 } else if (fmt.equalsIgnoreCase("long")) { 67 out.println(customer.getFirstName() + " " + 68 customer.getLastName() + " " + customer.getAddress()); 69 } else { 70 out.println("invalid format"); 71 } 72 } catch (IOException ex) {} 73 74 return SKIP_BODY; 75 } 76 77 public void release() { 79 super.release(); 80 init(); 81 } 82 83 86 90 public Customer getCustomer() { 91 return customer; 92 } 93 94 98 public void setCustomer(Customer customer) { 99 this.customer = customer; 100 } 101 102 106 public String getFmt() { 107 return fmt; 108 } 109 110 114 public void setFmt(String fmt) { 115 this.fmt = fmt; 116 } 117 } 118 | Popular Tags |