01: /* When.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Tue Sep 6 15:33:29 2005, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2005 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.web.servlet.dsp.action;
20:
21: import java.io.IOException;
22:
23: import org.zkoss.web.mesg.MWeb;
24: import org.zkoss.web.servlet.ServletException;
25:
26: /**
27: * Represents an alternative within a {@link Choose} action.
28: *
29: * @author tomyeh
30: */
31: public class When extends AbstractAction {
32: private boolean _cond;
33:
34: /** Returns the test result. */
35: public boolean getTest() {
36: return _cond;
37: }
38:
39: /** Sets the test result. */
40: public void setTest(boolean cond) {
41: _cond = cond;
42: }
43:
44: //-- Action --//
45: public void render(ActionContext ac, boolean nested)
46: throws javax.servlet.ServletException, IOException {
47: if (!isEffective())
48: return;
49:
50: final Action parent = ac.getParent();
51: if (!(parent instanceof Choose))
52: throw new ServletException(
53: "The parent of when must be choose");
54:
55: final Choose choose = (Choose) parent;
56: if (_cond && !choose.isMatched()) {
57: choose.setMatched(true);
58: if (nested)
59: ac.renderFragment(null);
60: }
61: }
62:
63: //-- Object --//
64: public String toString() {
65: return "otherwise";
66: }
67: }
|