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 twopagecrudtable;
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.webui.jsf.component.Body;
049: import com.sun.webui.jsf.component.Button;
050: import com.sun.webui.jsf.component.DropDown;
051: import com.sun.webui.jsf.component.Form;
052: import com.sun.webui.jsf.component.Head;
053: import com.sun.webui.jsf.component.Html;
054: import com.sun.webui.jsf.component.Label;
055: import com.sun.webui.jsf.component.Link;
056: import com.sun.webui.jsf.component.MessageGroup;
057: import com.sun.webui.jsf.component.Page;
058: import com.sun.webui.jsf.component.StaticText;
059: import com.sun.webui.jsf.component.Table;
060: import com.sun.webui.jsf.component.TableColumn;
061: import com.sun.webui.jsf.component.TableRowGroup;
062: import com.sun.webui.jsf.model.DefaultTableDataProvider;
063: import java.sql.SQLException;
064: import java.util.Date;
065: import javax.faces.FacesException;
066: import javax.faces.component.html.HtmlPanelGrid;
067: import javax.faces.convert.IntegerConverter;
068: import javax.faces.event.ValueChangeEvent;
069:
070: /**
071: * <p>Page bean that corresponds to a similarly named JSP page. This
072: * class contains component definitions (and initialization code) for
073: * all components that you have defined on this page, as well as
074: * lifecycle methods and event handlers where you may add behavior
075: * to respond to incoming events.</p>
076: */
077: public class Page1 extends AbstractPageBean {
078: // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
079: private int __placeholder;
080:
081: /**
082: * <p>Automatically managed component initialization. <strong>WARNING:</strong>
083: * This method is automatically generated, so any user-specified code inserted
084: * here is subject to being replaced.</p>
085: */
086: private void _init() throws Exception {
087: personDataProvider
088: .setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.personRowSet}"));
089: tripDataProvider
090: .setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.tripRowSet}"));
091: }
092:
093: private Page page1 = new Page();
094:
095: public Page getPage1() {
096: return page1;
097: }
098:
099: public void setPage1(Page p) {
100: this .page1 = p;
101: }
102:
103: private Html html1 = new Html();
104:
105: public Html getHtml1() {
106: return html1;
107: }
108:
109: public void setHtml1(Html h) {
110: this .html1 = h;
111: }
112:
113: private Head head1 = new Head();
114:
115: public Head getHead1() {
116: return head1;
117: }
118:
119: public void setHead1(Head h) {
120: this .head1 = h;
121: }
122:
123: private Link link1 = new Link();
124:
125: public Link getLink1() {
126: return link1;
127: }
128:
129: public void setLink1(Link l) {
130: this .link1 = l;
131: }
132:
133: private Body body1 = new Body();
134:
135: public Body getBody1() {
136: return body1;
137: }
138:
139: public void setBody1(Body b) {
140: this .body1 = b;
141: }
142:
143: private Form form1 = new Form();
144:
145: public Form getForm1() {
146: return form1;
147: }
148:
149: public void setForm1(Form f) {
150: this .form1 = f;
151: }
152:
153: private HtmlPanelGrid mainPanel = new HtmlPanelGrid();
154:
155: public HtmlPanelGrid getMainPanel() {
156: return mainPanel;
157: }
158:
159: public void setMainPanel(HtmlPanelGrid hpg) {
160: this .mainPanel = hpg;
161: }
162:
163: private HtmlPanelGrid personPanel = new HtmlPanelGrid();
164:
165: public HtmlPanelGrid getPersonPanel() {
166: return personPanel;
167: }
168:
169: public void setPersonPanel(HtmlPanelGrid hpg) {
170: this .personPanel = hpg;
171: }
172:
173: private HtmlPanelGrid tablePanel = new HtmlPanelGrid();
174:
175: public HtmlPanelGrid getTablePanel() {
176: return tablePanel;
177: }
178:
179: public void setTablePanel(HtmlPanelGrid hpg) {
180: this .tablePanel = hpg;
181: }
182:
183: private Label label1 = new Label();
184:
185: public Label getLabel1() {
186: return label1;
187: }
188:
189: public void setLabel1(Label l) {
190: this .label1 = l;
191: }
192:
193: private Label label2 = new Label();
194:
195: public Label getLabel2() {
196: return label2;
197: }
198:
199: public void setLabel2(Label l) {
200: this .label2 = l;
201: }
202:
203: private DropDown personDropDown = new DropDown();
204:
205: public DropDown getPersonDropDown() {
206: return personDropDown;
207: }
208:
209: public void setPersonDropDown(DropDown dd) {
210: this .personDropDown = dd;
211: }
212:
213: private StaticText jobTitleText = new StaticText();
214:
215: public StaticText getJobTitleText() {
216: return jobTitleText;
217: }
218:
219: public void setJobTitleText(StaticText st) {
220: this .jobTitleText = st;
221: }
222:
223: private Table tripsTable = new Table();
224:
225: public Table getTripsTable() {
226: return tripsTable;
227: }
228:
229: public void setTripsTable(Table t) {
230: this .tripsTable = t;
231: }
232:
233: private TableRowGroup tableRowGroup1 = new TableRowGroup();
234:
235: public TableRowGroup getTableRowGroup1() {
236: return tableRowGroup1;
237: }
238:
239: public void setTableRowGroup1(TableRowGroup trg) {
240: this .tableRowGroup1 = trg;
241: }
242:
243: private Button createButton = new Button();
244:
245: public Button getCreateButton() {
246: return createButton;
247: }
248:
249: public void setCreateButton(Button b) {
250: this .createButton = b;
251: }
252:
253: private MessageGroup messageGroup1 = new MessageGroup();
254:
255: public MessageGroup getMessageGroup1() {
256: return messageGroup1;
257: }
258:
259: public void setMessageGroup1(MessageGroup mg) {
260: this .messageGroup1 = mg;
261: }
262:
263: private CachedRowSetDataProvider personDataProvider = new CachedRowSetDataProvider();
264:
265: public CachedRowSetDataProvider getPersonDataProvider() {
266: return personDataProvider;
267: }
268:
269: public void setPersonDataProvider(CachedRowSetDataProvider crsdp) {
270: this .personDataProvider = crsdp;
271: }
272:
273: private IntegerConverter personDropDownConverter = new IntegerConverter();
274:
275: public IntegerConverter getPersonDropDownConverter() {
276: return personDropDownConverter;
277: }
278:
279: public void setPersonDropDownConverter(IntegerConverter ic) {
280: this .personDropDownConverter = ic;
281: }
282:
283: private CachedRowSetDataProvider tripDataProvider = new CachedRowSetDataProvider();
284:
285: public CachedRowSetDataProvider getTripDataProvider() {
286: return tripDataProvider;
287: }
288:
289: public void setTripDataProvider(CachedRowSetDataProvider crsdp) {
290: this .tripDataProvider = crsdp;
291: }
292:
293: private TableColumn tableColumn1 = new TableColumn();
294:
295: public TableColumn getTableColumn1() {
296: return tableColumn1;
297: }
298:
299: public void setTableColumn1(TableColumn tc) {
300: this .tableColumn1 = tc;
301: }
302:
303: private StaticText staticText1 = new StaticText();
304:
305: public StaticText getStaticText1() {
306: return staticText1;
307: }
308:
309: public void setStaticText1(StaticText st) {
310: this .staticText1 = st;
311: }
312:
313: private TableColumn tableColumn2 = new TableColumn();
314:
315: public TableColumn getTableColumn2() {
316: return tableColumn2;
317: }
318:
319: public void setTableColumn2(TableColumn tc) {
320: this .tableColumn2 = tc;
321: }
322:
323: private StaticText staticText2 = new StaticText();
324:
325: public StaticText getStaticText2() {
326: return staticText2;
327: }
328:
329: public void setStaticText2(StaticText st) {
330: this .staticText2 = st;
331: }
332:
333: private TableColumn tableColumn3 = new TableColumn();
334:
335: public TableColumn getTableColumn3() {
336: return tableColumn3;
337: }
338:
339: public void setTableColumn3(TableColumn tc) {
340: this .tableColumn3 = tc;
341: }
342:
343: private StaticText staticText3 = new StaticText();
344:
345: public StaticText getStaticText3() {
346: return staticText3;
347: }
348:
349: public void setStaticText3(StaticText st) {
350: this .staticText3 = st;
351: }
352:
353: private TableColumn tableColumn4 = new TableColumn();
354:
355: public TableColumn getTableColumn4() {
356: return tableColumn4;
357: }
358:
359: public void setTableColumn4(TableColumn tc) {
360: this .tableColumn4 = tc;
361: }
362:
363: private StaticText staticText4 = new StaticText();
364:
365: public StaticText getStaticText4() {
366: return staticText4;
367: }
368:
369: public void setStaticText4(StaticText st) {
370: this .staticText4 = st;
371: }
372:
373: private TableColumn tableColumn5 = new TableColumn();
374:
375: public TableColumn getTableColumn5() {
376: return tableColumn5;
377: }
378:
379: public void setTableColumn5(TableColumn tc) {
380: this .tableColumn5 = tc;
381: }
382:
383: private Button deleteButton = new Button();
384:
385: public Button getDeleteButton() {
386: return deleteButton;
387: }
388:
389: public void setDeleteButton(Button b) {
390: this .deleteButton = b;
391: }
392:
393: private Button updateButton = new Button();
394:
395: public Button getUpdateButton() {
396: return updateButton;
397: }
398:
399: public void setUpdateButton(Button b) {
400: this .updateButton = b;
401: }
402:
403: // </editor-fold>
404:
405: /**
406: * <p>Construct a new Page bean instance.</p>
407: */
408: public Page1() {
409: }
410:
411: /**
412: * <p>Callback method that is called whenever a page is navigated to,
413: * either directly via a URL, or indirectly via page navigation.
414: * Customize this method to acquire resources that will be needed
415: * for event handlers and lifecycle methods, whether or not this
416: * page is performing post back processing.</p>
417: *
418: * <p>Note that, if the current request is a postback, the property
419: * values of the components do <strong>not</strong> represent any
420: * values submitted with this request. Instead, they represent the
421: * property values that were saved for this view when it was rendered.</p>
422: */
423: @Override
424: public void init() {
425: // Perform initializations inherited from our superclass
426: super .init();
427: // Perform application initialization that must complete
428: // *before* managed components are initialized
429: // TODO - add your own initialiation code here
430:
431: // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
432: // Initialize automatically managed components
433: // *Note* - this logic should NOT be modified
434: try {
435: _init();
436: } catch (Exception e) {
437: log("Page1 Initialization Failure", e);
438: throw e instanceof FacesException ? (FacesException) e
439: : new FacesException(e);
440: }
441:
442: // </editor-fold>
443: // Perform application initialization that must complete
444: // *after* managed components are initialized
445: // TODO - add your own initialization code here
446: //set minimum and maximum dates allowed for trips
447: Date minDate = new Date(99, 0, 1);
448: getSessionBean1().setMinDate(minDate);
449:
450: Date maxDate = new Date(108, 11, 31);
451: getSessionBean1().setMaxDate(maxDate);
452:
453: // Restore the current person and trip
454: Integer pid = getSessionBean1().getCurrentPersonId();
455: tripDataProvider.refresh();
456: if (pid == null) {
457: personDataProvider.cursorFirst();
458: pid = (Integer) personDataProvider
459: .getValue("PERSON.PERSONID");
460: try {
461: getSessionBean1().getTripRowSet().setObject(1, pid);
462: getSessionBean1().getTripRowSet().execute();
463: tripDataProvider.cursorFirst();
464: } catch (Exception ex) {
465: log("Error Description", ex);
466: }
467: } else {
468: RowKey personRowKey = personDataProvider.findFirst(
469: "PERSON.PERSONID", pid);
470: personDataProvider.setCursorRow(personRowKey);
471: }
472: personDropDown.setSelected(pid);
473: }
474:
475: /**
476: * <p>Callback method that is called after the component tree has been
477: * restored, but before any event processing takes place. This method
478: * will <strong>only</strong> be called on a postback request that
479: * is processing a form submit. Customize this method to allocate
480: * resources that will be required in your event handlers.</p>
481: */
482: @Override
483: public void preprocess() {
484: }
485:
486: /**
487: * <p>Callback method that is called just before rendering takes place.
488: * This method will <strong>only</strong> be called for the page that
489: * will actually be rendered (and not, for example, on a page that
490: * handled a postback and then navigated to a different page). Customize
491: * this method to allocate resources that will be required for rendering
492: * this page.</p>
493: */
494: @Override
495: public void prerender() {
496: }
497:
498: /**
499: * <p>Callback method that is called after rendering is completed for
500: * this request, if <code>init()</code> was called (regardless of whether
501: * or not this was the page that was actually rendered). Customize this
502: * method to release resources acquired in the <code>init()</code>,
503: * <code>preprocess()</code>, or <code>prerender()</code> methods (or
504: * acquired during execution of an event handler).</p>
505: */
506: @Override
507: public void destroy() {
508: // Save away the current cursor position
509: Integer pid = (Integer) personDataProvider
510: .getValue("PERSON.PERSONID");
511: getSessionBean1().setCurrentPersonId(pid);
512: personDataProvider.close();
513: tripDataProvider.close();
514: }
515:
516: /**
517: * <p>Return a reference to the scoped data bean.</p>
518: */
519: protected SessionBean1 getSessionBean1() {
520: return (SessionBean1) getBean("SessionBean1");
521: }
522:
523: /**
524: * <p>Return a reference to the scoped data bean.</p>
525: */
526: protected ApplicationBean1 getApplicationBean1() {
527: return (ApplicationBean1) getBean("ApplicationBean1");
528: }
529:
530: /**
531: * <p>Return a reference to the scoped data bean.</p>
532: */
533: protected RequestBean1 getRequestBean1() {
534: return (RequestBean1) getBean("RequestBean1");
535: }
536:
537: public void personDropDown_processValueChange(ValueChangeEvent event) {
538: Integer newPersonId = (Integer) personDropDown.getSelected();
539: // Find the datatable's row that matches the dropdown's
540: // selected person
541: RowKey rowKey = personDataProvider.findFirst("PERSON.PERSONID",
542: newPersonId);
543: // just in case someone deleted row after dropdown was populated
544: if (rowKey != null) {
545: try {
546: // change cursor position
547: personDataProvider.setCursorRow(rowKey);
548: getSessionBean1().getTripRowSet().setObject(1,
549: newPersonId);
550: getSessionBean1().getTripRowSet().execute();
551: tripDataProvider.cursorFirst();
552: } catch (TableCursorVetoException tcve) {
553: error("Cannot change to personDropDown " + newPersonId);
554: } catch (SQLException sqle) {
555: error("Cannot retrieve trips");
556: }
557: } else {
558: // exceptional event we might want to know about
559: error("Missing person for personDropDown " + newPersonId);
560: }
561: }
562:
563: public String updateButton_action() {
564: // TODO: Process the action. Return value is a navigation
565: // case name where null will return to the same page.
566: RowKey rowKey = tableRowGroup1.getRowKey();
567: Integer tid = (Integer) tripDataProvider.getValue(
568: "TRIP.TRIPID", rowKey);
569: getSessionBean1().setCurrentTripId(tid);
570: return "updateCase";
571: }
572:
573: public String deleteButton_action() {
574: // TODO: Process the action. Return value is a navigation
575: // case name where null will return to the same page.travel
576: RowKey rowKey = tableRowGroup1.getRowKey();
577: try {
578: tripDataProvider.removeRow(rowKey);
579: tripDataProvider.commitChanges();
580: } catch (Exception e) {
581: error("Cannot delete trip with row key " + rowKey + e);
582: }
583: return null;
584: }
585:
586: public String createButton_action() {
587: // TODO: Process the action. Return value is a navigation
588: // case name where null will return to the same page.
589: getSessionBean1().setCurrentPersonId(
590: (Integer) personDropDown.getValue());
591: return "createCase";
592: }
593: }
|