01: /* Button.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Aug 8, 2007 5:48:27 PM 2007, Created by Dennis.Chen
10: }}IS_NOTE
11:
12: Copyright (C) 2007 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.jsf.zul;
20:
21: import java.io.IOException;
22: import java.io.StringWriter;
23:
24: import javax.faces.context.FacesContext;
25:
26: import org.zkoss.jsf.zul.impl.BaseCommand;
27: import org.zkoss.zk.ui.Component;
28: import org.zkoss.zul.impl.XulElement;
29:
30: /**
31: * Button is a JSF component implementation for {@link org.zkoss.zul.Button},
32: *
33: * This component should be declared nested under {@link org.zkoss.jsf.zul.Page}.
34: * This class also implements {@link javax.faces.component.ActionSource}.
35: * That means you can use action and actionListener features on this component.
36: * <br/>
37: * To use those features, you must declare a namespace of "http://java.sun.com/jsf/core"
38: * with a prefix (say 'f' in below example), add attribute of those feature with this namespace
39: * (for example f:required="true")in you jsf page.
40: * For more detail of ActionSource features of JSF, you can refer to <a href="http://java.sun.com/products/jsp/">http://java.sun.com/products/jsp/</a>
41: *
42: * <p/>
43: * Example of action :<br/>
44: * <pre><code>
45: * <z:button id="btn" label="submit" f:action="#{CommandBean.actionPerform}"/>
46: * </code></pre>
47: *
48: * <p/>
49: * Example of actionListener :<br/>
50: * <pre><code>
51: * <z:button id="btn" label="submit" f:actionListener="#{CommandBean.onActionPerform}"/>
52: * </code></pre>
53: * <p/>
54: * In some application server which doesn't support attribute namespace you can use attribute prefix 'f_' to replace attribute namespace
55: * <br/>
56: * For example,
57: * <pre>
58: * <z:button f_action="#{CommandBean.actionPerform}"/>
59: * </pre>
60: *
61: * <p/>
62: * <p/>To know more ZK component features you can refer to <a href="http://www.zkoss.org/">http://www.zkoss.org/</a>
63: *
64: * @author Dennis.Chen
65: *
66: */
67: public class Button extends BaseCommand {
68:
69: protected void loadZULTree(org.zkoss.zk.ui.Page page,
70: StringWriter writer) throws IOException {
71: super .loadZULTree(page, writer);
72: if (hasListener()) {
73: //add onclick action
74: org.zkoss.zul.Button comp = (org.zkoss.zul.Button) getZULComponent();
75: FacesContext context = FacesContext.getCurrentInstance();
76: String submitmethod = getJSSubmitMethodName(context);
77: String submitscript = getJSSubmitScript(context);
78: writer.write(submitscript);
79: String oa = comp.getAction();
80: comp.setAction((oa == null ? "" : oa + ";") + "onclick:"
81: + submitmethod + "();");
82: }
83: }
84: }
|