01: /* Set.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Tue Sep 6 15:11:19 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: * The set action used to set an attribute.
28: *
29: * @author tomyeh
30: */
31: public class Set extends AbstractAction {
32: private int _scope = ActionContext.PAGE_SCOPE;
33: private String _var;
34: private Object _val;
35:
36: /** Returns the scope. */
37: public int getScope() {
38: return _scope;
39: }
40:
41: /** Sets the scope. */
42: public void setScope(String scope) {
43: _scope = toScope(scope);
44: }
45:
46: /** Returns the attribute name. */
47: public String getVar() {
48: return _var;
49: }
50:
51: /** Sets the attribute name. */
52: public void setVar(String var) {
53: _var = var;
54: }
55:
56: /** Returns the attribute value. */
57: public Object getValue() {
58: return _val;
59: }
60:
61: /** Sets the attribute value. */
62: public void setValue(Object val) {
63: _val = val;
64: }
65:
66: //-- Action --//
67: public void render(ActionContext ac, boolean nested)
68: throws javax.servlet.ServletException, IOException {
69: if (!isEffective())
70: return;
71: if (nested)
72: throw new ServletException(
73: MWeb.DSP_NESTED_ACTION_NOT_ALLOWED, new Object[] {
74: this , new Integer(ac.getLineNumber()) });
75: if (_var == null)
76: throw new ServletException(MWeb.DSP_ATTRIBUTE_REQUIRED,
77: new Object[] { this , "var",
78: new Integer(ac.getLineNumber()) });
79: ac.setAttribute(_var, _val, _scope);
80: }
81:
82: //-- Object --//
83: public String toString() {
84: return "set";
85: }
86: }
|