Source Code Cross Referenced for WCrudPage.java in  » Database-ORM » SimpleORM » simpleorm » simplewebapp » eg » simple » 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 » Database ORM » SimpleORM » simpleorm.simplewebapp.eg.simple 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package simpleorm.simplewebapp.eg.simple;
002:
003:        import simpleorm.simplewebapp.core.*;
004:        import simpleorm.simplewebapp.scalarFields.WFieldString;
005:        import simpleorm.simplewebapp.scalarFields.WFieldDate;
006:        import simpleorm.simplewebapp.scalarFields.WFieldInteger;
007:
008:        /**
009:         * A simple demonstration of a CRUD page.
010:         * The implementation of the logic is very manual, see WUserAutoCrudPage
011:         * for a more automated version.<p>
012:         *
013:         * (This is subtyped by WManualCrudPage and WAutoCrudPage just to
014:         * demonstrate two ways of implementing JSPs.  This style would not normally be
015:         * subtyped at all.)
016:         */
017:        public class WCrudPage extends WPage {
018:
019:            public final WCrudPagelet pagelet = new WCrudPagelet(this );
020:
021:            /**
022:             * NOT necessary, just here to demonstrate.
023:             * This is accessesed as ${wPage.id} in ManualCrudTest.jsp
024:             * (Vs the normal ${wPage.fields.id}.)
025:             */
026:            public WField getId() {
027:                return pagelet.id;
028:            }
029:
030:            protected @Override
031:            void onInitialize() throws Exception {
032:                WTestDatabase.db.beginTransaction();
033:            }
034:
035:            protected @Override
036:            void onFinalize() throws Exception {
037:                WTestDatabase.db.endTransaction();
038:            }
039:
040:            public static class WCrudPagelet extends WPagelet {
041:                // Needs to be static class as newed by WManualListCrudPage
042:
043:                final WButton update = addNewButton("Update");
044:                final WButton delete = addNewButton("Delete");
045:                final WButton add = addNewButton("Add");
046:
047:                WFieldGroup identity = addGroup(this , new WFieldGroup(
048:                        "userIdentity"));
049:                final WFieldString id = addField(identity,
050:                        new WFieldString("id")).setRequired(true);
051:                final WField name = addField(identity,
052:                        new WFieldString("name").setDisplayLength(60))
053:                        .setRequired(true);
054:                final WField database = addField(identity, new WFieldString(
055:                        "database").setReadOnly(true));
056:
057:                WFieldGroup details = addGroup(this , new WFieldGroup(
058:                        "userDetails"));
059:                final WField color = addField(details, new WFieldString(
060:                        "color", WField.SELECT));
061:                final WField alignment = addField(details, new WFieldString(
062:                        "alignment", WField.RADIO));
063:                final WField happy = addField(details, new WFieldString(
064:                        "happy", WField.CHECKBOX));
065:                final WFieldInteger count = addField(details,
066:                        new WFieldInteger("count")).setRequired(true);
067:                final WFieldDate datefield = addField(details, new WFieldDate(
068:                        "datefield"));
069:
070:                public WCrudPagelet(WPage wpage) {
071:                    // wpage parameter rather than non-static inner class as also used from WManualListCrudPage
072:                    super (wpage, "crud");
073:                    //name.setPostedText("Mr Green");
074:                    color.getOptions().add("Red");
075:                    color.getOptions().add("Green");
076:                    color.getOptions().add("Blue");
077:                    //color.setPostedText("Green");
078:                    alignment.getOptions().add("Left");
079:                    alignment.getOptions().add("Middle");
080:                    alignment.getOptions().add("Right");
081:                    //alignment.setPostedText("Middle");
082:                }
083:
084:                /**
085:                 * Disables buttons before fields are validated.
086:                 * Needs to retrieve the row here before field validators in order
087:                 * to be able to set the buttons correctly.
088:                 * (The messy case is when a user attempts to add a row, enters
089:                 * an id, but has validation errors.)
090:                 */
091:                protected @Override
092:                void onPreValidate() throws Exception {
093:                    String theKey = id.getText(); // getValue() not available yet.
094:                    if (theKey == null) {
095:                        update.setDisabled(true);
096:                        delete.setDisabled(true);
097:                    } else
098:                        add.setDisabled(true);
099:                }
100:
101:                public @Override
102:                void onNotSubmitted() { // ie. initial display of form
103:                    // Fetch data here
104:                    String theId = id.getValue();
105:                    if (theId != null) {
106:                        WTestRecord row = (WTestRecord) WTestDatabase.db
107:                                .findRow(theId);
108:                        WBeanUtils.retrieveBeanProperties(row,
109:                                getAllFieldValues());
110:                        //fields.name.setValue(row.name);
111:                        //fields.color.setValue(row.color);
112:                        //fields.alignment.setValue(row.alignment);
113:                        //fields.happy.setValue(row.happy);
114:                        //fields.count.setValue(row.count);
115:                        //fields.datefield.setValue(row.datefield);
116:                    }
117:                }
118:
119:                public @Override
120:                void onWasSubmitted() { // ie. after a post back
121:                    String theId = id.getValue();
122:                    if (theId != null) {
123:                        WTestRecord row = (WTestRecord) WTestDatabase.db
124:                                .findRow(theId);
125:                        if (getSubmitButton() == update
126:                                || getSubmitButton() == add) {
127:                            int cv = count.getIntValue(0);
128:                            if (cv % 2 != 1)
129:                                throw new WValidationException(
130:                                        "Crud.CountMustBeOdd", count)
131:                                        .setParameter("" + cv);
132:                            if (row == null)
133:                                row = WTestDatabase.db.addRow(theId);
134:                            WBeanUtils.updateBeanProperties(row,
135:                                    getAllFieldValues());
136:                            //row.name = fields.name.getValue();
137:                            //row.color = fields.color.getValue();
138:                            //row.count = fields.count.getIntValue(0);
139:                            //row.datefield = fields.datefield.getDateValue(null);
140:                        } else if (getSubmitButton() == delete) {
141:                            if (row != null)
142:                                WTestDatabase.db.removeRow(row.idx);
143:                            nullAllFields();
144:                        }
145:                        // else throw new WException("Bad button " + getSubmitButton());
146:                        // no exception, it might be from a different pagelet.
147:                        //WTestDatabase.db.endTransaction();
148:                        // WTestDatabase.db.beginTransaction();
149:
150:                        getPageStructure().setActualRedirectUrl(
151:                                getPotentialSuccessUrl());
152:                    }
153:                }
154:
155:                protected @Override
156:                void onPostMaybeSubmitted() throws Exception {
157:                    database.setValue(WTestDatabase.db.getDatabaseName()); // Hibernate or in Memory
158:                }
159:            }
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.