Source Code Cross Referenced for NewUserWizard.java in  » J2EE » wicket » org » apache » wicket » examples » wizard » 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.examples.wizard 
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.examples.wizard;
018:
019:        import java.util.Arrays;
020:        import java.util.List;
021:
022:        import org.apache.wicket.extensions.wizard.StaticContentStep;
023:        import org.apache.wicket.extensions.wizard.Wizard;
024:        import org.apache.wicket.extensions.wizard.WizardModel;
025:        import org.apache.wicket.extensions.wizard.WizardStep;
026:        import org.apache.wicket.extensions.wizard.WizardModel.ICondition;
027:        import org.apache.wicket.markup.html.form.CheckBox;
028:        import org.apache.wicket.markup.html.form.Form;
029:        import org.apache.wicket.markup.html.form.FormComponent;
030:        import org.apache.wicket.markup.html.form.ListMultipleChoice;
031:        import org.apache.wicket.markup.html.form.RequiredTextField;
032:        import org.apache.wicket.markup.html.form.TextField;
033:        import org.apache.wicket.markup.html.form.validation.AbstractFormValidator;
034:        import org.apache.wicket.model.CompoundPropertyModel;
035:        import org.apache.wicket.model.IModel;
036:        import org.apache.wicket.model.Model;
037:        import org.apache.wicket.model.ResourceModel;
038:        import org.apache.wicket.model.StringResourceModel;
039:        import org.apache.wicket.validation.IValidationError;
040:        import org.apache.wicket.validation.ValidationError;
041:        import org.apache.wicket.validation.validator.EmailAddressValidator;
042:
043:        /**
044:         * This wizard shows some basic form use. It uses custom panels for the form
045:         * elements, and a single domain object ({@link User}) as it's subject. Also,
046:         * the user roles step}is an optional step, that will only be executed when
047:         * assignRoles is true (and that value is edited in the user details step).
048:         * 
049:         * @author Eelco Hillenius
050:         */
051:        public class NewUserWizard extends Wizard {
052:            /**
053:             * The confirmation step.
054:             */
055:            private final class ConfirmationStep extends StaticContentStep {
056:                /**
057:                 * Construct.
058:                 */
059:                public ConfirmationStep() {
060:                    super (true);
061:                    IModel userModel = new Model(user);
062:                    setTitleModel(new ResourceModel("confirmation.title"));
063:                    setSummaryModel(new StringResourceModel(
064:                            "confirmation.summary", this , userModel));
065:                    setContentModel(new StringResourceModel(
066:                            "confirmation.content", this , userModel));
067:                }
068:            }
069:
070:            /**
071:             * The user details step.
072:             */
073:            private final class UserDetailsStep extends WizardStep {
074:                /**
075:                 * Construct.
076:                 */
077:                public UserDetailsStep() {
078:                    setTitleModel(new ResourceModel("confirmation.title"));
079:                    setSummaryModel(new StringResourceModel(
080:                            "userdetails.summary", this , new Model(user)));
081:                    add(new RequiredTextField("user.firstName"));
082:                    add(new RequiredTextField("user.lastName"));
083:                    add(new TextField("user.department"));
084:                    add(new CheckBox("assignRoles"));
085:                }
086:            }
087:
088:            /**
089:             * The user name step.
090:             */
091:            private final class UserNameStep extends WizardStep {
092:                /**
093:                 * Construct.
094:                 */
095:                public UserNameStep() {
096:                    super (new ResourceModel("username.title"),
097:                            new ResourceModel("username.summary"));
098:                    add(new RequiredTextField("user.userName"));
099:                    add(new RequiredTextField("user.email")
100:                            .add(EmailAddressValidator.getInstance()));
101:                }
102:            }
103:
104:            /**
105:             * The user details step.
106:             */
107:            private final class UserRolesStep extends WizardStep implements 
108:                    ICondition {
109:                /**
110:                 * Construct.
111:                 */
112:                public UserRolesStep() {
113:                    super (new ResourceModel("userroles.title"), null);
114:                    setSummaryModel(new StringResourceModel(
115:                            "userroles.summary", this , new Model(user)));
116:                    final ListMultipleChoice rolesChoiceField = new ListMultipleChoice(
117:                            "user.roles", allRoles);
118:                    add(rolesChoiceField);
119:                    final TextField rolesSetNameField = new TextField(
120:                            "user.rolesSetName");
121:                    add(rolesSetNameField);
122:                    add(new AbstractFormValidator() {
123:                        public FormComponent[] getDependentFormComponents() {
124:                            // name and roles don't have anything to validate,
125:                            // so might as well just skip them here
126:                            return null;
127:                        }
128:
129:                        public void validate(Form form) {
130:                            String rolesInput = rolesChoiceField.getInput();
131:                            if (rolesInput != null && (!"".equals(rolesInput))) {
132:                                if ("".equals(rolesSetNameField.getInput())) {
133:                                    rolesSetNameField
134:                                            .error((IValidationError) new ValidationError()
135:                                                    .addMessageKey("error.noSetNameForRoles"));
136:                                }
137:                            }
138:                        }
139:                    });
140:                }
141:
142:                /**
143:                 * @see org.apache.wicket.extensions.wizard.WizardModel.ICondition#evaluate()
144:                 */
145:                public boolean evaluate() {
146:                    return assignRoles;
147:                }
148:            }
149:
150:            /** cheap ass roles database. */
151:            private static final List<String> allRoles = Arrays
152:                    .asList(new String[] { "admin", "user", "moderator",
153:                            "joker", "slacker" });
154:
155:            /** Whether the assign roles step should be executed. */
156:            private boolean assignRoles = false;
157:
158:            /** The user we are editing. */
159:            private User user;
160:
161:            /**
162:             * Construct.
163:             * 
164:             * @param id
165:             *            The component id
166:             */
167:            public NewUserWizard(String id) {
168:                super (id);
169:
170:                // create a blank user
171:                user = new User();
172:
173:                setModel(new CompoundPropertyModel(this ));
174:                WizardModel model = new WizardModel();
175:                model.add(new UserNameStep());
176:                model.add(new UserDetailsStep());
177:                model.add(new UserRolesStep());
178:                model.add(new ConfirmationStep());
179:
180:                // initialize the wizard with the wizard model we just built
181:                init(model);
182:            }
183:
184:            /**
185:             * Gets user.
186:             * 
187:             * @return user
188:             */
189:            public User getUser() {
190:                return user;
191:            }
192:
193:            /**
194:             * Gets assignRoles.
195:             * 
196:             * @return assignRoles
197:             */
198:            public boolean isAssignRoles() {
199:                return assignRoles;
200:            }
201:
202:            /**
203:             * @see org.apache.wicket.extensions.wizard.Wizard#onCancel()
204:             */
205:            public void onCancel() {
206:                setResponsePage(Index.class);
207:            }
208:
209:            /**
210:             * @see org.apache.wicket.extensions.wizard.Wizard#onFinish()
211:             */
212:            public void onFinish() {
213:                setResponsePage(Index.class);
214:            }
215:
216:            /**
217:             * Sets assignRoles.
218:             * 
219:             * @param assignRoles
220:             *            assignRoles
221:             */
222:            public void setAssignRoles(boolean assignRoles) {
223:                this .assignRoles = assignRoles;
224:            }
225:
226:            /**
227:             * Sets user.
228:             * 
229:             * @param user
230:             *            user
231:             */
232:            public void setUser(User user) {
233:                this.user = user;
234:            }
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.