/* Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
This code is for educational purposes only. Use at own risk.*/

1. <%@ taglib 

2.    uri="taglib.tld" 

3.    prefix = "preafigs" 

4. %> 

5.   

6. <HTML

7. <HEAD

8. <TITLE

9. JSP Custom tags 2 

10. </TITLE

11. </HEAD

12.  

13. <BODY

14. <H1>Our footer, as a Custom Tag with an attribute</H1

15.  

16. <preafigs:SEMMsFTAttr  pobox="yes" color="FF0080"

17.  

18. Added text in body

19.  

20. </preafigs:SEMMsFTAttr> 

21.  

22. </BODY

23. </HTML

24.  

25. ========  taglib.tld  ============================== 

26.  

27. (.....same as previous ) 

28.  

29.   <tag> 

30.     <name>SEMMsFooter</name> 

31.     <tagclass>nl.semm.tags.SEMMsFooterTag</tagclass> 

32.     <info> Footer </info> 

33.   </tag> 

34.  

35.  

36.   <tag> 

37.     <name>SEMMsFTAttr</name> 

38.     <tagclass>nl.semm.tags.SEMMsFTAttr</tagclass> 

39.     <info> Footer with attribute</info> 

40.  

41.     <attribute> 

42.       <name>pobox</name> 

43.       <required>false</required> 

44.     </attribute> 

45.  

46.     <attribute> 

47.       <name>color</name> 

48.       <required>false</required> 

49.     </attribute> 

50.  

51.   </tag> 

52.  

53. (.......) 

54. ========  SEMMsFTAttr.java  ============================== 

55.  

56. package nl.semm.tags; 

57. import javax.servlet.jsp.*; 

58. import javax.servlet.jsp.tagext.*; 

59. import java.util.Calendar

60.  

61. public class SEMMsFTAttr 

62.   extends TagSupport 

63.

64.   private String pobox = "false"

65.   private String color = null

66.  

67.   public String getPobox() 

68.   { 

69.     return pobox ; 

70.   } 

71.   public void setPobox( String pob ) 

72.   { 

73.     if ( pob.equalsIgnoreCase("yes") ) 

74.       pobox = "true"

75.   } 

76.  

77.   public String getColor() 

78.   { 

79.     return color ; 

80.   } 

81.   public void setColor ( String col ) 

82.   { 

83.     try

84.     Integer.decode( "0x" + col ) ; 

85.  

86.     color = col ; 

87.     } 

88.     catch ( NumberFormatException ex ) 

89.     { } 

90.   } 

91.  

92.  

93.   public int doStartTag() 

94.   throws JspException 

95.     { 

96.     try

97.       JspWriter jspout = pageContext.getOut() ; 

98.  

99.       if ( color != null

100.       { 

101.         jspout.print( "<font color=\"#" ) ; 

102.         jspout.print( color ) ; 

103.         jspout.print( "\">" ); 

104.       } 

105.       Calendar now = Calendar.getInstance() ; 

106.  

107.       jspout.print ( "<CENTER>"  ) ; 

108.       jspout.print ( "<HR>" ) ; 

109.       jspout.print ( "Generated " ) ; 

110.       jspout.print (  now.getTime() ) ; 

111.       jspout.print ( "."  ) ; 

112.       jspout.print ( "<HR>"  ) ; 

113.       jspout.print ( "Copyright © " ) ; 

114.       jspout.print (  now.get(Calendar.YEAR)  ) ; 

115.       jspout.print ( " SEMM (NL) " ) ; 

116.  

117.       if ( pobox.equalsIgnoreCase("true") ) 

118.         jspout.print ( "<BR>P.O.Box 65432." ); 

119.     } 

120.     catch ( Exception ex ) 

121.     { 

122.       throw new JspException("Problem : " + ex ); 

123.     } 

124.     return EVAL_BODY_INCLUDE

125.   } 

126.  

127.   public int doEndTag() 

128.   throws JspException 

129.     { 

130.     try

131.       JspWriter jspout = pageContext.getOut() ; 

132.       jspout.print ( "<HR>"  ) ; 

133.       jspout.print ( "</CENTER>"  ) ; 

134.       if ( color != null

135.         jspout.print( "</font>" ); 

136.     } 

137.     catch ( Exception ex ) 

138.     { 

139.       throw new JspException("Problem : " + ex ); 

140.     } 

141.     return EVAL_PAGE

142.   } 

143.

144.