Source Code Cross Referenced for SubmitLink.java in  » J2EE » wicket » org » apache » wicket » markup » html » form » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » wicket » org.apache.wicket.markup.html.form 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.wicket.markup.html.form;
018:
019:        import org.apache.wicket.markup.ComponentTag;
020:        import org.apache.wicket.model.IModel;
021:
022:        /**
023:         * A link which can be used exactly like a Button to submit a Form. The href of
024:         * the link will use JavaScript to submit the form.
025:         * 
026:         * <p>
027:         * You can use this class 2 ways. First with the constructor without a Form
028:         * object then this Link must be inside a Form so that it knows what form to
029:         * submit to. Second way is to use the Form constructor then that form will be
030:         * used to submit to.
031:         * </p>
032:         * <p>
033:         * <pre>
034:         *     Form f = new Form(&quot;linkForm&quot;, new CompoundPropertyModel(mod));
035:         *     f.add(new TextField(&quot;value1&quot;));
036:         *     f.add(new SubmitLink(&quot;link1&quot;) {
037:         *         protected void onSubmit() {
038:         *             System.out.println(&quot;Link1 was clicked, value1 is: &quot;
039:         *                                 + mod.getValue1());
040:         *         };
041:         *      });
042:         *      add(new SubmitLink(&quot;link2&quot;,f) {
043:         *          protected void onSubmit() {
044:         *              System.out.println(&quot;Link2 was clicked, value1 is: &quot;
045:         *                                 + mod.getValue1());
046:         *           };
047:         *      });
048:         *          
049:         *      &lt;form wicket:id=&quot;linkForm&quot; &gt;
050:         *          &lt;input wicket:id=&quot;value1&quot; type=&quot;text&quot; size=&quot;30&quot;/&gt;
051:         *          &lt;a wicket:id=&quot;link1&quot;&gt;Press link1 to submit&lt;/a&gt;
052:         *          &lt;input type=&quot;submit&quot; value=&quot;Send&quot;/&gt;
053:         *      &lt;/form&gt;
054:         *      &lt;a wicket:id=&quot;link2&quot;&gt;Press link 2 to submit&lt;/a&gt;
055:         * </pre>
056:         * </p>
057:         * <p>
058:         * If this link is not placed in a form or given a form to cooperate with, it will
059:         * fall back to a normal link behavior, meaning that {@link #onSubmit()} will be called
060:         * without any other consequences.
061:         * </p>
062:         * 
063:         * @author chris
064:         * @author jcompagner
065:         * @author Igor Vaynberg (ivaynberg)
066:         * @author Eelco Hillenius
067:         */
068:        public class SubmitLink extends AbstractSubmitLink {
069:            private static final long serialVersionUID = 1L;
070:
071:            /**
072:             * With this constructor the SubmitLink must be inside a Form.
073:             * 
074:             * @param id
075:             *            The id of the submitlink.
076:             */
077:            public SubmitLink(String id) {
078:                super (id);
079:            }
080:
081:            /**
082:             * With this constructor the SubmitLink will submit the {@link Form} that is
083:             * given when the link is clicked on.
084:             * 
085:             * The SubmitLink doesn't have to be in inside the {@link Form}. But
086:             * currently if it is outside the {@link Form} and the SubmitLink will be
087:             * rendered first. Then the {@link Form} will have a generated
088:             * javascript/css id. The markup javascript/css id that can exist will be
089:             * overridden.
090:             * 
091:             * @param id
092:             *            The id of the submitlink.
093:             * @param form
094:             *            The form which this submitlink must submit.
095:             */
096:            public SubmitLink(String id, Form form) {
097:                super (id, form);
098:            }
099:
100:            /**
101:             * With this constructor the SubmitLink must be inside a Form.
102:             * 
103:             * @param id
104:             *            The id of the submitlink.
105:             * @param model
106:             *            The model for this submitlink, It won't be used by the submit
107:             *            link itself, but it can be used for keeping state
108:             */
109:            public SubmitLink(String id, IModel model) {
110:                super (id, model);
111:            }
112:
113:            /**
114:             * With this constructor the SubmitLink will submit the {@link Form} that is
115:             * given when the link is clicked on.
116:             * 
117:             * The SubmitLink doesn't have to be in inside the {@link Form}. But
118:             * currently if it is outside the {@link Form} and the SubmitLink will be
119:             * rendered first. Then the {@link Form} will have a generated
120:             * javascript/css id. The markup javascript/css id that can exist will be
121:             * overridden.
122:             * 
123:             * @param id
124:             *            The id of the submitlink.
125:             * @param model
126:             *            The model for this submitlink, It won't be used by the submit
127:             *            link itself, but it can be used for keeping state
128:             * @param form
129:             *            The form which this submitlink must submit.
130:             */
131:            public SubmitLink(String id, IModel model, Form form) {
132:                super (id, model, form);
133:            }
134:
135:            /**
136:             * This method is here as a means to fall back on normal link
137:             * behavior when this link is not nested in a form. Not intended
138:             * to be called by clients directly.
139:             * @see org.apache.wicket.markup.html.link.ILinkListener#onLinkClicked()
140:             */
141:            public final void onLinkClicked() {
142:                onSubmit();
143:            }
144:
145:            /**
146:             * @inheritDoc
147:             * @see org.apache.wicket.Component#onComponentTag(org.apache.wicket.markup.ComponentTag)
148:             */
149:            protected void onComponentTag(ComponentTag tag) {
150:                super .onComponentTag(tag);
151:                // If we're disabled
152:                if (!isLinkEnabled()) {
153:                    disableLink(tag);
154:                } else {
155:                    if (tag.getName().equalsIgnoreCase("a")) {
156:                        tag.put("href", "#");
157:                    }
158:                    tag.put("onclick", getTriggerJavaScript());
159:                }
160:            }
161:
162:            /**
163:             * Controls whether or not clicking on this link will invoke form's
164:             * javascript onsubmit handler. True by default.
165:             * 
166:             * @return true if form's javascript onsubmit handler should be invoked,
167:             *         false otherwise
168:             */
169:            protected boolean shouldInvokeJavascriptFormOnsubmit() {
170:                return true;
171:            }
172:
173:            /**
174:             * The javascript which trigges this link.
175:             * 
176:             * TODO: This is a copy & paste from Button
177:             * 
178:             * @return The javascript
179:             */
180:            protected final String getTriggerJavaScript() {
181:                if (getForm() != null) {
182:                    // find the root form - the one we are really going to submit
183:                    Form root = getForm().getRootForm();
184:                    StringBuffer sb = new StringBuffer(100);
185:                    sb.append("var e=document.getElementById('");
186:                    sb.append(root.getHiddenFieldId());
187:                    sb.append("'); e.name=\'");
188:                    sb.append(getInputName());
189:                    sb.append("'; e.value='x';");
190:                    sb.append("var f=document.getElementById('");
191:                    sb.append(root.getMarkupId());
192:                    sb.append("');");
193:                    if (shouldInvokeJavascriptFormOnsubmit()) {
194:                        if (getForm() != root) {
195:                            sb.append("var ff=document.getElementById('");
196:                            sb.append(getForm().getMarkupId());
197:                            sb.append("');");
198:                        } else {
199:                            sb.append("var ff=f;");
200:                        }
201:                        sb
202:                                .append("if (ff.onsubmit != undefined) { if (ff.onsubmit()==false) return false; }");
203:                    }
204:                    sb.append("f.submit();e.value='';e.name='';return false;");
205:                    return sb.toString();
206:                } else {
207:                    return null;
208:                }
209:            }
210:
211:            /**
212:             * @see org.apache.wicket.markup.html.form.IFormSubmittingComponent#onSubmit()
213:             */
214:            public void onSubmit() {
215:            }
216:
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.