Source Code Cross Referenced for Page1.java in  » IDE-Netbeans » visualweb.api.designer » singlepagecrudform » 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 » IDE Netbeans » visualweb.api.designer » singlepagecrudform 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package singlepagecrudform;
043:
044:        import com.sun.data.provider.RowKey;
045:        import com.sun.data.provider.TableCursorVetoException;
046:        import com.sun.data.provider.impl.CachedRowSetDataProvider;
047:        import com.sun.rave.web.ui.appbase.AbstractPageBean;
048:        import com.sun.sql.rowset.CachedRowSetXImpl;
049:        import com.sun.webui.jsf.component.Body;
050:        import com.sun.webui.jsf.component.Button;
051:        import com.sun.webui.jsf.component.Calendar;
052:        import com.sun.webui.jsf.component.DropDown;
053:        import com.sun.webui.jsf.component.Form;
054:        import com.sun.webui.jsf.component.Head;
055:        import com.sun.webui.jsf.component.Html;
056:        import com.sun.webui.jsf.component.Label;
057:        import com.sun.webui.jsf.component.Link;
058:        import com.sun.webui.jsf.component.Message;
059:        import com.sun.webui.jsf.component.MessageGroup;
060:        import com.sun.webui.jsf.component.Page;
061:        import com.sun.webui.jsf.component.StaticText;
062:        import com.sun.webui.jsf.component.TextField;
063:        import java.sql.SQLException;
064:        import javax.faces.FacesException;
065:        import javax.faces.application.FacesMessage;
066:        import javax.faces.component.UIComponent;
067:        import javax.faces.component.UIInput;
068:        import javax.faces.component.html.HtmlPanelGrid;
069:        import javax.faces.context.FacesContext;
070:        import javax.faces.convert.IntegerConverter;
071:        import javax.faces.event.ValueChangeEvent;
072:        import javax.faces.validator.ValidatorException;
073:
074:        /**
075:         * <p>Page bean that corresponds to a similarly named JSP page.  This
076:         * class contains component definitions (and initialization code) for
077:         * all components that you have defined on this page, as well as
078:         * lifecycle methods and event handlers where you may add behavior
079:         * to respond to incoming events.</p>
080:         */
081:        public class Page1 extends AbstractPageBean {
082:            // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
083:            private int __placeholder;
084:
085:            /**
086:             * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
087:             * This method is automatically generated, so any user-specified code inserted
088:             * here is subject to being replaced.</p>
089:             */
090:            private void _init() throws Exception {
091:                personDataProvider
092:                        .setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.personRowSet}"));
093:                tripDataProvider
094:                        .setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.tripRowSet}"));
095:                triptypeDataProvider
096:                        .setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.triptypeRowSet}"));
097:            }
098:
099:            private Page page1 = new Page();
100:
101:            public Page getPage1() {
102:                return page1;
103:            }
104:
105:            public void setPage1(Page p) {
106:                this .page1 = p;
107:            }
108:
109:            private Html html1 = new Html();
110:
111:            public Html getHtml1() {
112:                return html1;
113:            }
114:
115:            public void setHtml1(Html h) {
116:                this .html1 = h;
117:            }
118:
119:            private Head head1 = new Head();
120:
121:            public Head getHead1() {
122:                return head1;
123:            }
124:
125:            public void setHead1(Head h) {
126:                this .head1 = h;
127:            }
128:
129:            private Link link1 = new Link();
130:
131:            public Link getLink1() {
132:                return link1;
133:            }
134:
135:            public void setLink1(Link l) {
136:                this .link1 = l;
137:            }
138:
139:            private Body body1 = new Body();
140:
141:            public Body getBody1() {
142:                return body1;
143:            }
144:
145:            public void setBody1(Body b) {
146:                this .body1 = b;
147:            }
148:
149:            private Form form1 = new Form();
150:
151:            public Form getForm1() {
152:                return form1;
153:            }
154:
155:            public void setForm1(Form f) {
156:                this .form1 = f;
157:            }
158:
159:            private HtmlPanelGrid mainPanel = new HtmlPanelGrid();
160:
161:            public HtmlPanelGrid getMainPanel() {
162:                return mainPanel;
163:            }
164:
165:            public void setMainPanel(HtmlPanelGrid hpg) {
166:                this .mainPanel = hpg;
167:            }
168:
169:            private HtmlPanelGrid personForm = new HtmlPanelGrid();
170:
171:            public HtmlPanelGrid getPersonForm() {
172:                return personForm;
173:            }
174:
175:            public void setPersonForm(HtmlPanelGrid hpg) {
176:                this .personForm = hpg;
177:            }
178:
179:            private HtmlPanelGrid tripForm = new HtmlPanelGrid();
180:
181:            public HtmlPanelGrid getTripForm() {
182:                return tripForm;
183:            }
184:
185:            public void setTripForm(HtmlPanelGrid hpg) {
186:                this .tripForm = hpg;
187:            }
188:
189:            private HtmlPanelGrid crudControls = new HtmlPanelGrid();
190:
191:            public HtmlPanelGrid getCrudControls() {
192:                return crudControls;
193:            }
194:
195:            public void setCrudControls(HtmlPanelGrid hpg) {
196:                this .crudControls = hpg;
197:            }
198:
199:            private Button create = new Button();
200:
201:            public Button getCreate() {
202:                return create;
203:            }
204:
205:            public void setCreate(Button b) {
206:                this .create = b;
207:            }
208:
209:            private Button save = new Button();
210:
211:            public Button getSave() {
212:                return save;
213:            }
214:
215:            public void setSave(Button b) {
216:                this .save = b;
217:            }
218:
219:            private Button cancel = new Button();
220:
221:            public Button getCancel() {
222:                return cancel;
223:            }
224:
225:            public void setCancel(Button b) {
226:                this .cancel = b;
227:            }
228:
229:            private Button delete = new Button();
230:
231:            public Button getDelete() {
232:                return delete;
233:            }
234:
235:            public void setDelete(Button b) {
236:                this .delete = b;
237:            }
238:
239:            private HtmlPanelGrid vcrControls = new HtmlPanelGrid();
240:
241:            public HtmlPanelGrid getVcrControls() {
242:                return vcrControls;
243:            }
244:
245:            public void setVcrControls(HtmlPanelGrid hpg) {
246:                this .vcrControls = hpg;
247:            }
248:
249:            private Button first = new Button();
250:
251:            public Button getFirst() {
252:                return first;
253:            }
254:
255:            public void setFirst(Button b) {
256:                this .first = b;
257:            }
258:
259:            private Button prev = new Button();
260:
261:            public Button getPrev() {
262:                return prev;
263:            }
264:
265:            public void setPrev(Button b) {
266:                this .prev = b;
267:            }
268:
269:            private Button next = new Button();
270:
271:            public Button getNext() {
272:                return next;
273:            }
274:
275:            public void setNext(Button b) {
276:                this .next = b;
277:            }
278:
279:            private Button last = new Button();
280:
281:            public Button getLast() {
282:                return last;
283:            }
284:
285:            public void setLast(Button b) {
286:                this .last = b;
287:            }
288:
289:            private Label label1 = new Label();
290:
291:            public Label getLabel1() {
292:                return label1;
293:            }
294:
295:            public void setLabel1(Label l) {
296:                this .label1 = l;
297:            }
298:
299:            private Label label2 = new Label();
300:
301:            public Label getLabel2() {
302:                return label2;
303:            }
304:
305:            public void setLabel2(Label l) {
306:                this .label2 = l;
307:            }
308:
309:            private Label label3 = new Label();
310:
311:            public Label getLabel3() {
312:                return label3;
313:            }
314:
315:            public void setLabel3(Label l) {
316:                this .label3 = l;
317:            }
318:
319:            private Label label4 = new Label();
320:
321:            public Label getLabel4() {
322:                return label4;
323:            }
324:
325:            public void setLabel4(Label l) {
326:                this .label4 = l;
327:            }
328:
329:            private Calendar depDateCalendar = new Calendar();
330:
331:            public Calendar getDepDateCalendar() {
332:                return depDateCalendar;
333:            }
334:
335:            public void setDepDateCalendar(Calendar c) {
336:                this .depDateCalendar = c;
337:            }
338:
339:            private Message message1 = new Message();
340:
341:            public Message getMessage1() {
342:                return message1;
343:            }
344:
345:            public void setMessage1(Message m) {
346:                this .message1 = m;
347:            }
348:
349:            private TextField fromCity = new TextField();
350:
351:            public TextField getFromCity() {
352:                return fromCity;
353:            }
354:
355:            public void setFromCity(TextField tf) {
356:                this .fromCity = tf;
357:            }
358:
359:            private TextField toCity = new TextField();
360:
361:            public TextField getToCity() {
362:                return toCity;
363:            }
364:
365:            public void setToCity(TextField tf) {
366:                this .toCity = tf;
367:            }
368:
369:            private Message message2 = new Message();
370:
371:            public Message getMessage2() {
372:                return message2;
373:            }
374:
375:            public void setMessage2(Message m) {
376:                this .message2 = m;
377:            }
378:
379:            private Message message3 = new Message();
380:
381:            public Message getMessage3() {
382:                return message3;
383:            }
384:
385:            public void setMessage3(Message m) {
386:                this .message3 = m;
387:            }
388:
389:            private DropDown tripType = new DropDown();
390:
391:            public DropDown getTripType() {
392:                return tripType;
393:            }
394:
395:            public void setTripType(DropDown dd) {
396:                this .tripType = dd;
397:            }
398:
399:            private MessageGroup messageGroup1 = new MessageGroup();
400:
401:            public MessageGroup getMessageGroup1() {
402:                return messageGroup1;
403:            }
404:
405:            public void setMessageGroup1(MessageGroup mg) {
406:                this .messageGroup1 = mg;
407:            }
408:
409:            private Label person = new Label();
410:
411:            public Label getPerson() {
412:                return person;
413:            }
414:
415:            public void setPerson(Label l) {
416:                this .person = l;
417:            }
418:
419:            private Label title1 = new Label();
420:
421:            public Label getTitle1() {
422:                return title1;
423:            }
424:
425:            public void setTitle1(Label l) {
426:                this .title1 = l;
427:            }
428:
429:            private DropDown personId = new DropDown();
430:
431:            public DropDown getPersonId() {
432:                return personId;
433:            }
434:
435:            public void setPersonId(DropDown dd) {
436:                this .personId = dd;
437:            }
438:
439:            private StaticText title = new StaticText();
440:
441:            public StaticText getTitle() {
442:                return title;
443:            }
444:
445:            public void setTitle(StaticText st) {
446:                this .title = st;
447:            }
448:
449:            private CachedRowSetDataProvider personDataProvider = new CachedRowSetDataProvider();
450:
451:            public CachedRowSetDataProvider getPersonDataProvider() {
452:                return personDataProvider;
453:            }
454:
455:            public void setPersonDataProvider(CachedRowSetDataProvider crsdp) {
456:                this .personDataProvider = crsdp;
457:            }
458:
459:            private IntegerConverter personIdConverter = new IntegerConverter();
460:
461:            public IntegerConverter getPersonIdConverter() {
462:                return personIdConverter;
463:            }
464:
465:            public void setPersonIdConverter(IntegerConverter ic) {
466:                this .personIdConverter = ic;
467:            }
468:
469:            private CachedRowSetDataProvider tripDataProvider = new CachedRowSetDataProvider();
470:
471:            public CachedRowSetDataProvider getTripDataProvider() {
472:                return tripDataProvider;
473:            }
474:
475:            public void setTripDataProvider(CachedRowSetDataProvider crsdp) {
476:                this .tripDataProvider = crsdp;
477:            }
478:
479:            private CachedRowSetDataProvider triptypeDataProvider = new CachedRowSetDataProvider();
480:
481:            public CachedRowSetDataProvider getTriptypeDataProvider() {
482:                return triptypeDataProvider;
483:            }
484:
485:            public void setTriptypeDataProvider(CachedRowSetDataProvider crsdp) {
486:                this .triptypeDataProvider = crsdp;
487:            }
488:
489:            private IntegerConverter tripTypeConverter = new IntegerConverter();
490:
491:            public IntegerConverter getTripTypeConverter() {
492:                return tripTypeConverter;
493:            }
494:
495:            public void setTripTypeConverter(IntegerConverter ic) {
496:                this .tripTypeConverter = ic;
497:            }
498:
499:            // </editor-fold>
500:
501:            /**
502:             * <p>Construct a new Page bean instance.</p>
503:             */
504:            public Page1() {
505:            }
506:
507:            /**
508:             * <p>Callback method that is called whenever a page is navigated to,
509:             * either directly via a URL, or indirectly via page navigation.
510:             * Customize this method to acquire resources that will be needed
511:             * for event handlers and lifecycle methods, whether or not this
512:             * page is performing post back processing.</p>
513:             * 
514:             * <p>Note that, if the current request is a postback, the property
515:             * values of the components do <strong>not</strong> represent any
516:             * values submitted with this request.  Instead, they represent the
517:             * property values that were saved for this view when it was rendered.</p>
518:             */
519:            @Override
520:            public void init() {
521:                // Perform initializations inherited from our superclass
522:                super .init();
523:                // Perform application initialization that must complete
524:                // *before* managed components are initialized
525:                // TODO - add your own initialiation code here
526:
527:                // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
528:                // Initialize automatically managed components
529:                // *Note* - this logic should NOT be modified
530:                try {
531:                    _init();
532:                } catch (Exception e) {
533:                    log("Page1 Initialization Failure", e);
534:                    throw e instanceof  FacesException ? (FacesException) e
535:                            : new FacesException(e);
536:                }
537:
538:                // </editor-fold>
539:                // Perform application initialization that must complete
540:                // *after* managed components are initialized
541:                // TODO - add your own initialization code here
542:                Integer pid = getSessionBean1().getPersonId();
543:                Integer tid = getSessionBean1().getTripId();
544:                if (pid == null) {
545:                    // i.e., first time this page is rendered
546:                    personDataProvider.cursorFirst();
547:                    pid = (Integer) personDataProvider
548:                            .getValue("PERSON.PERSONID");
549:                    try {
550:                        // get trips for this person
551:                        getSessionBean1().getTripRowSet().setObject(1, pid);
552:                        getSessionBean1().getTripRowSet().execute();
553:                    } catch (SQLException sqle) {
554:                        error("Page1::init() -- problem getting trips for the current personId");
555:                        throw new FacesException(sqle);
556:                    }
557:                    tripDataProvider.cursorFirst();
558:                    //tid = (Integer) tripDataProvider.getValue("TRIP.TRIPID");
559:                } else {
560:                    RowKey personRowKey = personDataProvider.findFirst(
561:                            "PERSON.PERSONID", pid);
562:                    personDataProvider.setCursorRow(personRowKey);
563:                    // make sure the person has trips, before looking for data
564:                    if (getSessionBean1().getTripRowSet().size() > 0) {
565:                        if (tid == null) {
566:                            tripDataProvider.cursorFirst();
567:                        } else {
568:                            RowKey tripRowKey = tripDataProvider.findFirst(
569:                                    "TRIP.TRIPID", tid);
570:                            tripDataProvider.setCursorRow(tripRowKey);
571:                        }
572:                    }
573:                }
574:                personId.setSelected(pid);
575:            }
576:
577:            /**
578:             * <p>Callback method that is called after the component tree has been
579:             * restored, but before any event processing takes place.  This method
580:             * will <strong>only</strong> be called on a postback request that
581:             * is processing a form submit.  Customize this method to allocate
582:             * resources that will be required in your event handlers.</p>
583:             */
584:            @Override
585:            public void preprocess() {
586:            }
587:
588:            /**
589:             * <p>Callback method that is called just before rendering takes place.
590:             * This method will <strong>only</strong> be called for the page that
591:             * will actually be rendered (and not, for example, on a page that
592:             * handled a postback and then navigated to a different page).  Customize
593:             * this method to allocate resources that will be required for rendering
594:             * this page.</p>
595:             */
596:            @Override
597:            public void prerender() {
598:                boolean tripsFlag = getSessionBean1().getTripRowSet().size() > 0;
599:                // make sure there are trips for the current person before accessing
600:                // data in the rowset
601:                if (tripsFlag) {
602:                    java.sql.Date date = (java.sql.Date) tripDataProvider
603:                            .getValue("TRIP.DEPDATE");
604:                    depDateCalendar.setValue(date);
605:                } else {
606:                    depDateCalendar.setValue(null);
607:                }
608:                boolean addingTrip = getSessionBean1().isAddingTrip();
609:                // stop user from appending two rows
610:                create.setDisabled(addingTrip);
611:                save.setDisabled(!tripsFlag);
612:                // the reset button only makes sense while inserting a record
613:                // and before committing the new record
614:                cancel.setDisabled(!addingTrip);
615:                // don't use delete while adding a record
616:                delete.setDisabled(addingTrip);
617:                // disable the VCR controls while we're inserting a record
618:                // to keep the user from navigating
619:                first.setDisabled(addingTrip);
620:                prev.setDisabled(addingTrip);
621:                next.setDisabled(addingTrip);
622:                last.setDisabled(addingTrip);
623:            }
624:
625:            /**
626:             * <p>Callback method that is called after rendering is completed for
627:             * this request, if <code>init()</code> was called (regardless of whether
628:             * or not this was the page that was actually rendered).  Customize this
629:             * method to release resources acquired in the <code>init()</code>,
630:             * <code>preprocess()</code>, or <code>prerender()</code> methods (or
631:             * acquired during execution of an event handler).</p>
632:             */
633:            @Override
634:            public void destroy() {
635:                // get PKs for each current record and store them in Session Bean
636:                Integer pid = (Integer) personDataProvider
637:                        .getValue("PERSON.PERSONID");
638:                getSessionBean1().setPersonId(pid);
639:                Integer tid = (Integer) tripDataProvider
640:                        .getValue("TRIP.TRIPID");
641:                getSessionBean1().setTripId(tid);
642:                personDataProvider.close();
643:                tripDataProvider.close();
644:                triptypeDataProvider.close();
645:            }
646:
647:            /**
648:             * <p>Return a reference to the scoped data bean.</p>
649:             */
650:            protected SessionBean1 getSessionBean1() {
651:                return (SessionBean1) getBean("SessionBean1");
652:            }
653:
654:            /**
655:             * <p>Return a reference to the scoped data bean.</p>
656:             */
657:            protected RequestBean1 getRequestBean1() {
658:                return (RequestBean1) getBean("RequestBean1");
659:            }
660:
661:            /**
662:             * <p>Return a reference to the scoped data bean.</p>
663:             */
664:            protected ApplicationBean1 getApplicationBean1() {
665:                return (ApplicationBean1) getBean("ApplicationBean1");
666:            }
667:
668:            public void personId_processValueChange(ValueChangeEvent event) {
669:                // TODO: Replace with your code
670:                if (getSessionBean1().isAddingTrip()) {
671:                    getSessionBean1().setAddingTrip(false);
672:                    try {
673:                        tripDataProvider.revertChanges();
674:                    } catch (Exception ex) {
675:                        error("Cannot revert changes to TRAVEL.TRIP table.");
676:                    }
677:                }
678:                Integer newPersonId = (Integer) personId.getSelected();
679:                // Find the datatable's row that matches the dropdown's selected person
680:                RowKey rowKey = personDataProvider.findFirst("PERSON.PERSONID",
681:                        newPersonId);
682:                // just in case someone deleted row after dropdown was populated
683:                if (rowKey != null) {
684:                    try {
685:                        // change cursor position
686:                        personDataProvider.setCursorRow(rowKey);
687:                        getSessionBean1().getTripRowSet().setObject(1,
688:                                newPersonId);
689:                        getSessionBean1().getTripRowSet().execute();
690:                        tripDataProvider.cursorFirst();
691:                    } catch (TableCursorVetoException tcve) {
692:                        error("Cannot change to personId " + newPersonId);
693:                    } catch (SQLException sqle) {
694:                        error("SQL excpetion");
695:                    }
696:                } else {
697:                    // exceptional event we might want to know about
698:                    error("Missing person for personId " + newPersonId);
699:                }
700:                form1.discardSubmittedValues("saveVForm");
701:            }
702:
703:            public String first_action() {
704:                // TODO: Process the action. Return value is a navigation
705:                // case name where null will return to the same page.
706:                getTripDataProvider().cursorFirst();
707:                form1.discardSubmittedValues("saveVForm");
708:                return null;
709:            }
710:
711:            public String prev_action() {
712:                // TODO: Process the action. Return value is a navigation
713:                // case name where null will return to the same page.
714:                getTripDataProvider().cursorPrevious();
715:                form1.discardSubmittedValues("saveVForm");
716:                return null;
717:            }
718:
719:            public String next_action() {
720:                // TODO: Process the action. Return value is a navigation
721:                // case name where null will return to the same page.
722:                getTripDataProvider().cursorNext();
723:                form1.discardSubmittedValues("saveVForm");
724:                return null;
725:            }
726:
727:            public String last_action() {
728:                // TODO: Process the action. Return value is a navigation
729:                // case name where null will return to the same page.
730:                getTripDataProvider().cursorLast();
731:                form1.discardSubmittedValues("saveVForm");
732:                return null;
733:            }
734:
735:            public String create_action() {
736:                // TODO: Process the action. Return value is a navigation
737:                // case name where null will return to the same page.
738:                try {
739:                    if (tripDataProvider.canAppendRow()) {
740:                        RowKey rowKey = tripDataProvider.appendRow();
741:                        tripDataProvider.setCursorRow(rowKey);
742:                        Integer tripPK = nextPK();
743:                        tripDataProvider.setValue("TRIP.TRIPID", tripPK);
744:                        getSessionBean1().setAddingTrip(true);
745:                    } else {
746:                        error("Page1::createButton_action() -- cannot append trip record");
747:                    }
748:                } catch (Exception e) {
749:                    error("Page1::createButton_action() -- something's wrong trying to append trip record");
750:                }
751:                form1.discardSubmittedValues("saveVForm");
752:                return null;
753:            }
754:
755:            // Generate an integer Primary Key
756:            // Return next primary key for TRAVEL.TRIP table
757:            private Integer nextPK() throws SQLException {
758:                // create a new rowset
759:                CachedRowSetXImpl pkRowSet = new CachedRowSetXImpl();
760:                try {
761:                    // set the rowset to use the Travel database
762:                    pkRowSet
763:                            .setDataSourceName("java:comp/env/jdbc/TRAVEL_ApacheDerby");
764:                    // find the highest person id and add one to it
765:                    pkRowSet
766:                            .setCommand("SELECT MAX(TRAVEL.TRIP.TRIPID) + 1 FROM TRAVEL.TRIP");
767:                    pkRowSet.setTableName("TRAVEL.TRIP");
768:                    // execute the rowset -- which will contain a single row and single column
769:                    pkRowSet.execute();
770:                    pkRowSet.next();
771:                    // get the key
772:                    int counter = pkRowSet.getInt(1);
773:                    return new Integer(counter);
774:                } catch (Exception e) {
775:                    error("Error fetching Max(TRAVEL.TRIP.TRIPID) + 1 : "
776:                            + e.getMessage());
777:                } finally {
778:                    pkRowSet.close();
779:                }
780:                return null;
781:            }
782:
783:            public String save_action() {
784:                // TODO: Process the action. Return value is a navigation
785:                // case name where null will return to the same page.
786:                try {
787:                    Integer tid = (Integer) tripDataProvider
788:                            .getValue("TRIP.TRIPID");
789:                    java.util.Date uDate = (java.util.Date) depDateCalendar
790:                            .getValue();
791:                    if (uDate != null) {
792:                        java.sql.Date date = new java.sql.Date(uDate.getTime());
793:                        tripDataProvider.setValue("TRIP.DEPDATE", date);
794:                    } else {
795:                        tripDataProvider.setValue("TRIP.DEPDATE", null);
796:                    }
797:                    if (getSessionBean1().isAddingTrip()) {
798:                        Integer pid = (Integer) personId.getValue();
799:                        tripDataProvider.setValue("TRIP.PERSONID", pid);
800:                        tripDataProvider.setValue("TRIP.TRIPTYPEID", tripType
801:                                .getSelected());
802:                        getSessionBean1().setAddingTrip(false);
803:                    }
804:                    tripDataProvider.commitChanges();
805:                    tripDataProvider.refresh();
806:                    // find the trip just added, and show it in the form
807:                    RowKey rk = tripDataProvider.findFirst("TRIP.TRIPID", tid);
808:                    tripDataProvider.setCursorRow(rk);
809:                } catch (Exception e) {
810:                    error("Save failed -- cannot commit changes -- " + e);
811:                }
812:                return null;
813:            }
814:
815:            public String cancel_action() {
816:                // TODO: Process the action. Return value is a navigation
817:                // case name where null will return to the same page.
818:                try {
819:                    if (getSessionBean1().isAddingTrip()) {
820:                        getSessionBean1().setAddingTrip(false);
821:                    }
822:                    tripDataProvider.revertChanges();
823:                    tripDataProvider.refresh();
824:                    tripDataProvider.cursorFirst();
825:                } catch (Exception ex) {
826:                    error("Cannot reset form");
827:                }
828:                form1.discardSubmittedValues("saveVForm");
829:                return null;
830:            }
831:
832:            public String delete_action() {
833:                // TODO: Process the action. Return value is a navigation
834:                // case name where null will return to the same page.
835:                Integer tid = getSessionBean1().getTripId();
836:                RowKey rk = null;
837:                // are there any trips for this person?
838:                if (getSessionBean1().getTripRowSet().size() > 0) {
839:                    rk = tripDataProvider.findFirst("TRIP.TRIPID", tid);
840:                    if (tripDataProvider.canRemoveRow(rk)) {
841:                        try {
842:                            tripDataProvider.cursorFirst();
843:                            tripDataProvider.removeRow(rk);
844:                            tripDataProvider.commitChanges();
845:                            tripDataProvider.refresh();
846:                            tripDataProvider.cursorFirst();
847:                        } catch (Exception ex) {
848:                            error("Cannot delete trip record "
849:                                    + tripDataProvider.getValue(
850:                                            "TRIP.TRIPTYPEID", rk));
851:                        }
852:                    } else {
853:                        error("Cannot delete trip records from database");
854:                    }
855:                }
856:                form1.discardSubmittedValues("saveVForm");
857:                return null;
858:            }
859:
860:            private void excludeDigits(UIComponent component, Object value) {
861:                String cityName = (String) value;
862:                for (int i = 0; i < cityName.length(); i++) {
863:                    if (Character.isDigit(cityName.charAt(i))) {
864:                        ((UIInput) component).setValid(false);
865:                        throw new ValidatorException(new FacesMessage(
866:                                "Error: City must contain no digits"));
867:                    }
868:                }
869:            }
870:
871:            public void fromCity_validate(FacesContext context,
872:                    UIComponent component, Object value) {
873:                // TODO: Replace with your code
874:                excludeDigits(component, value);
875:            }
876:
877:            public void toCity_validate(FacesContext context,
878:                    UIComponent component, Object value) {
879:                // TODO: Replace with your code
880:                excludeDigits(component, value);
881:            }
882:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.