KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > plaf > css > FormCG


1 /*
2  * $Id: FormCG.java,v 1.21 2005/05/26 13:18:09 neurolabs Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.plaf.css;
15
16
17 import org.wings.*;
18 import org.wings.io.Device;
19 import org.wings.session.SessionManager;
20
21 import java.io.IOException JavaDoc;
22
23 public class FormCG extends AbstractComponentCG implements org.wings.plaf.FormCG {
24
25     private static final SIcon BLIND_ICON = (SIcon) SessionManager.getSession()
26             .getCGManager().getObject("FormCG.blindIcon", SIcon.class);
27     
28     protected void writeContent(final Device device, final SComponent c) throws IOException JavaDoc {
29         final SForm component = (SForm) c;
30
31         device.print("<form method=\"");
32         if (component.isPostMethod()) {
33             device.print("POST");
34         } else {
35             device.print("GET");
36         }
37         device.print("\"");
38
39         Utils.optAttribute(device, "name", component.getName());
40         Utils.writeEvents(device, component);
41         Utils.optAttribute(device, "class", component.getStyle());
42         Utils.optAttribute(device, "enctype", component.getEncodingType());
43         Utils.optAttribute(device, "action", component.getRequestURL());
44
45         Utils.printCSSInlineFullSize(device, component.getPreferredSize());
46
47         /*
48         * we render two icons into the page that captures pressing simple 'return'
49         * in the page. Why ? Depending on the Browser, the Browser sends the
50         * first or the last submit-button it finds in the page as 'default'-Submit
51         * when we simply press 'return' somewhere.
52         *
53         * However, we don't want to have this arbitrary behaviour in wingS.
54         * So we add these two (invisible image-) submit-Buttons, either of it
55         * gets triggered on simple 'return'. No real wingS-Button will then be
56         * triggered but only the ActionListener added to the SForm. So we have
57         * a way to distinguish between Forms that have been sent as default and
58         * pressed buttons.
59         *
60         * Watchout: the style of these images once had been changed to display:none;
61         * to prevent taking some pixel renderspace. However, display:none; made
62         * the Internet Explorer not accept this as an input getting the default-focus,
63         * so it fell back to the old behaviour. So changed that style to no-padding,
64         * no-margin, no-whatever (HZ).
65         */

66         device.print("><input type=\"image\" name=\"_capture_enter1\" border=\"0\" ");
67         Utils.optAttribute(device, "src", BLIND_ICON.getURL());
68         device.print(" width=\"0\" height=\"0\" tabindex=\"\" style=\"border:none;padding:0px;margin:0px;position:absolute\"/>");
69
70         // Not sure: Think this was for optionally expiring old GET views?!
71
device.print("<input type=\"hidden\" name=\"");
72         Utils.write(device, Utils.event(component));
73         device.print("\" value=\"");
74         Utils.write(device, component.getName());
75         Utils.write(device, SConstants.UID_DIVIDER);
76         device.print("\" />");
77
78         // Render the container itself
79
Utils.renderContainer(device, component);
80
81         // Enter capture at end of form
82
device.print("<input type=\"image\" name=\"_capture_enter2\" border=\"0\" ");
83         Utils.optAttribute(device, "src", BLIND_ICON.getURL());
84         device.print(" width=\"0\" height=\"0\" tabindex=\"\" style=\"border:none;padding:0px;margin:0px;position:absolute\"/>");
85
86         device.print("</form>");
87     }
88
89 }
90
Popular Tags