Source Code Cross Referenced for PersonAddEditWidget.java in  » Web-Framework » aranea-mvc-1.1.1 » org » araneaframework » example » main » web » person » 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 » Web Framework » aranea mvc 1.1.1 » org.araneaframework.example.main.web.person 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright 2006 Webmedia Group Ltd.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *  http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         **/package org.araneaframework.example.main.web.person;
016:
017:        import org.araneaframework.example.main.TemplateBaseWidget;
018:        import org.araneaframework.example.main.business.model.PersonMO;
019:        import org.araneaframework.uilib.form.BeanFormWidget;
020:        import org.araneaframework.uilib.form.control.DateControl;
021:        import org.araneaframework.uilib.form.control.FloatControl;
022:        import org.araneaframework.uilib.form.control.TextControl;
023:
024:        /**
025:         * This widget is for adding new or editing existing persons.
026:         * Upon successful completion it returns the ID of stored person. 
027:         * 
028:         * @author <a href="mailto:rein@araneaframework.org">Rein Raudjärv</a>
029:         */
030:        public class PersonAddEditWidget extends TemplateBaseWidget {
031:            private static final long serialVersionUID = 1L;
032:            /* The ID field of the person data model, only has value if object has already
033:              been saved to/loaded from database. */
034:            private Long personId = null;
035:            // Whether the person is being edited or added
036:            private boolean editMode;
037:
038:            /* The form. Person data (represented by class PersonMO) will be binded to it, thus 
039:               usage of BeanFormWidget instead of FormWidget. */
040:            private BeanFormWidget form;
041:
042:            /**
043:             * Constructor for adding new person.
044:             */
045:            public PersonAddEditWidget() {
046:            }
047:
048:            /**
049:             * Constructor for editing existing person with specified Id.
050:             * @param personId Person's Id.
051:             */
052:            public PersonAddEditWidget(Long id) {
053:                this .personId = id;
054:                editMode = true;
055:            }
056:
057:            protected void init() throws Exception {
058:                // Sets the view selector that will be used for rendering this widget. */ 
059:                setViewSelector("person/personAddEdit");
060:                // This viewdata is used in JSP to set component header (different for editing and adding). 
061:                putViewData("label", editMode ? "person.edit.form.label"
062:                        : "person.add.form.label");
063:
064:                form = buildPersonEditForm();
065:                addWidget("personForm", form);
066:            }
067:
068:            private BeanFormWidget buildPersonEditForm() throws Exception {
069:                /* Create the form, specifying the class of data that is binded to this form. */
070:                BeanFormWidget form = new BeanFormWidget(PersonMO.class);
071:
072:                /* Adding the elements is done like in our SimpleFormWidget example, except
073:                 * that Data type is determined from bean class automatically and specifying
074:                 * it is not needed. */
075:
076:                //BeanFormWidget.addBeanElement(String elementName, String labelId, Control control, boolean mandatory)
077:                form.addBeanElement("name", "#First name", new TextControl(),
078:                        true);
079:                form.addBeanElement("surname", "#Last name", new TextControl(),
080:                        false);
081:                form.addBeanElement("phone", "#Phone no", new TextControl(),
082:                        true);
083:                form.addBeanElement("birthdate", "#Birthdate",
084:                        new DateControl(), false);
085:                form.addBeanElement("salary", "#Salary", new FloatControl(),
086:                        false);
087:
088:                if (editMode) {
089:                    /* fetch the person with given ID from database */
090:                    PersonMO person = (PersonMO) getGeneralDAO().getById(
091:                            PersonMO.class, personId);
092:                    /* and fill the form with current person data */
093:                    form.readFromBean(person);
094:                } /* otherwise we have no data and all form fields are initially left blank */
095:
096:                return form;
097:            }
098:
099:            public void handleEventSave(String eventParameter) throws Exception {
100:                // if form data is found to be valid  
101:                if (form.convertAndValidate()) {
102:                    // get the current person data (retrieved from database by getGeneralDAO() in case person already has assigned ID); 
103:                    PersonMO person = personId != null ? (PersonMO) getGeneralDAO()
104:                            .getById(PersonMO.class, personId)
105:                            : new PersonMO();
106:                    // read the application user supplied data from form into model object.
107:                    person = (PersonMO) form.writeToBean(person);
108:
109:                    if (editMode) {
110:                        // updates person object in database
111:                        getGeneralDAO().edit(person);
112:                    } else {
113:                        // saves new person object to database
114:                        personId = getGeneralDAO().add(person);
115:                    }
116:
117:                    /* finish current flow execution and return to calling flow, returning database ID 
118:                     * of added or edited person */
119:                    getFlowCtx().finish(personId);
120:                } else {
121:                    /* Do nothing, error messages are applied to MessageContext by validating methods 
122:                     * so that application user receives immediate feedback about incorrectly filled
123:                     * form elements automatically. */
124:                }
125:            }
126:
127:            /* Cancels the adding/editing of current person, returns to calling flow */
128:            public void handleEventCancel(String eventParameter)
129:                    throws Exception {
130:                getFlowCtx().cancel();
131:            }
132:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.