KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > views > jsp > IfTag


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.views.jsp;
6
7 import javax.servlet.jsp.JspException JavaDoc;
8
9
10 /**
11  * @author $Author: plightbo $
12  * @version $Revision: 1.9 $
13  */

14 public class IfTag extends WebWorkTagSupport {
15     //~ Static fields/initializers /////////////////////////////////////////////
16

17     public static final String JavaDoc ANSWER = "webwork.if.answer";
18
19     //~ Instance fields ////////////////////////////////////////////////////////
20

21     Boolean JavaDoc answer;
22     String JavaDoc test;
23
24     //~ Methods ////////////////////////////////////////////////////////////////
25

26     public void setTest(String JavaDoc test) {
27         this.test = test;
28     }
29
30     public int doEndTag() throws JspException JavaDoc {
31         pageContext.setAttribute(ANSWER, answer);
32
33         return SKIP_BODY;
34     }
35
36     public int doStartTag() throws JspException JavaDoc {
37         answer = (Boolean JavaDoc) findValue(test, Boolean JavaDoc.class);
38
39         if (answer == null) {
40             answer = Boolean.FALSE;
41         }
42
43         if (answer.booleanValue()) {
44             return EVAL_BODY_INCLUDE;
45         } else {
46             return SKIP_BODY;
47         }
48     }
49 }
50
Popular Tags