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