Source Code Cross Referenced for AjaxFormSubmitBehavior.java in  » J2EE » wicket » org » apache » wicket » ajax » 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.ajax.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.ajax.form;
018:
019:        import org.apache.wicket.Component;
020:        import org.apache.wicket.Page;
021:        import org.apache.wicket.ajax.AjaxEventBehavior;
022:        import org.apache.wicket.ajax.AjaxRequestTarget;
023:        import org.apache.wicket.markup.html.form.Form;
024:        import org.apache.wicket.markup.html.form.IFormSubmittingComponent;
025:        import org.apache.wicket.util.string.AppendingStringBuffer;
026:
027:        /**
028:         * Ajax event behavior that submits a form via ajax when the event it is
029:         * attached to is invoked.
030:         * <p>
031:         * The form must have an id attribute in the markup or have MarkupIdSetter
032:         * added.
033:         * 
034:         * @see AjaxEventBehavior
035:         * 
036:         * @since 1.2
037:         * 
038:         * @author Igor Vaynberg (ivaynberg)
039:         * 
040:         */
041:        public abstract class AjaxFormSubmitBehavior extends AjaxEventBehavior {
042:            private static final long serialVersionUID = 1L;
043:
044:            private Form form;
045:
046:            /**
047:             * Constructor. This constructor can only be used when the component this
048:             * behavior is attached to is inside a form.
049:             * 
050:             * @param event
051:             *            javascript event this behavior is attached to, like onclick
052:             */
053:            public AjaxFormSubmitBehavior(String event) {
054:                this (null, event);
055:            }
056:
057:            /**
058:             * Construct.
059:             * 
060:             * @param form
061:             *            form that will be submitted
062:             * @param event
063:             *            javascript event this behavior is attached to, like onclick
064:             */
065:            public AjaxFormSubmitBehavior(Form form, String event) {
066:                super (event);
067:                this .form = form;
068:
069:                if (form != null) {
070:                    form.setOutputMarkupId(true);
071:                }
072:            }
073:
074:            private Form getForm() {
075:                if (form == null) {
076:                    // try to find form in the hierarchy of owning component
077:                    Component cursor = getComponent();
078:                    while (cursor != null && !(cursor instanceof  Form)) {
079:                        cursor = cursor.getParent();
080:                    }
081:                    if (cursor == null) {
082:                        throw new IllegalStateException(
083:                                "form was not specified in the constructor and cannot "
084:                                        + "be found in the hierarchy of the component this behavior "
085:                                        + "is attached to");
086:                    } else {
087:                        form = (Form) cursor;
088:                    }
089:                }
090:                return form;
091:            }
092:
093:            protected CharSequence getEventHandler() {
094:                final String formId = getForm().getMarkupId();
095:                final CharSequence url = getCallbackUrl();
096:
097:                AppendingStringBuffer call = new AppendingStringBuffer(
098:                        "wicketSubmitFormById('").append(formId).append("', '")
099:                        .append(url).append("', ");
100:
101:                if (getComponent() instanceof  IFormSubmittingComponent) {
102:                    call.append("'").append(
103:                            ((IFormSubmittingComponent) getComponent())
104:                                    .getInputName()).append("' ");
105:                } else {
106:                    call.append("null");
107:                }
108:
109:                return generateCallbackScript(call) + ";";
110:            }
111:
112:            protected void onEvent(AjaxRequestTarget target) {
113:                getForm().onFormSubmitted();
114:                if (!getForm().hasError()) {
115:                    onSubmit(target);
116:                }
117:                if (form.findParent(Page.class) != null) {
118:                    /*
119:                     * there can be cases when a form is replaced with another component
120:                     * in the onsubmit() handler of this behavior. in that case form no
121:                     * longer has a page and so calling .hasError on it will cause an
122:                     * exception, thus the check above.
123:                     */
124:                    if (getForm().hasError()) {
125:                        onError(target);
126:                    }
127:                }
128:            }
129:
130:            /**
131:             * Listener method that is invoked after the form has ben submitted and
132:             * processed without errors
133:             * 
134:             * @param target
135:             */
136:            protected abstract void onSubmit(AjaxRequestTarget target);
137:
138:            /**
139:             * Listener method invoked when the form has been processed and errors
140:             * occured
141:             * 
142:             * @param target
143:             * 
144:             * TODO 1.3: make abstract to be consistent with onsubmit()
145:             * 
146:             */
147:            protected void onError(AjaxRequestTarget target) {
148:
149:            }
150:
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.