KickJava   Java API By Example, From Geeks To Geeks.

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


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 Rick Salsa (rsal@mb.sympatico.ca)
12  * @version $Revision: 1.8 $
13  */

14 public class ElseIfTag extends WebWorkTagSupport {
15     //~ Instance fields ////////////////////////////////////////////////////////
16

17     protected Boolean JavaDoc answer;
18     protected String JavaDoc test;
19
20     //~ Methods ////////////////////////////////////////////////////////////////
21

22     public void setTest(String JavaDoc test) {
23         this.test = test;
24     }
25
26     public int doEndTag() throws JspException JavaDoc {
27         if (answer == null) {
28             answer = new Boolean JavaDoc(false);
29         }
30
31         if (answer.booleanValue()) {
32             pageContext.setAttribute(IfTag.ANSWER, answer);
33         }
34
35         return SKIP_BODY;
36     }
37
38     public int doStartTag() throws JspException JavaDoc {
39         Boolean JavaDoc ifResult = (Boolean JavaDoc) pageContext.getAttribute(IfTag.ANSWER);
40
41         if ((ifResult == null) || (ifResult.booleanValue() == true)) {
42             return SKIP_BODY;
43         }
44
45         //make the comparision
46
answer = (Boolean JavaDoc) findValue(test, Boolean JavaDoc.class);
47
48         if (answer != null && answer.booleanValue()) {
49             return EVAL_BODY_INCLUDE;
50         }
51
52         return SKIP_BODY;
53     }
54 }
55
Popular Tags