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 vehicleincidentreportapplication;
043:
044: import com.sun.data.provider.RowKey;
045: import com.sun.data.provider.impl.CachedRowSetDataProvider;
046: import com.sun.rave.web.ui.appbase.AbstractPageBean;
047: import com.sun.sql.rowset.CachedRowSetXImpl;
048: import com.sun.webui.jsf.component.Body;
049: import com.sun.webui.jsf.component.Button;
050: import com.sun.webui.jsf.component.Form;
051: import com.sun.webui.jsf.component.Head;
052: import com.sun.webui.jsf.component.Html;
053: import com.sun.webui.jsf.component.Link;
054: import com.sun.webui.jsf.component.MessageGroup;
055: import com.sun.webui.jsf.component.Page;
056: import com.sun.webui.jsf.component.StaticText;
057: import com.sun.webui.jsf.component.Table;
058: import com.sun.webui.jsf.component.TableColumn;
059: import com.sun.webui.jsf.component.TableRowGroup;
060: import com.sun.webui.jsf.model.DefaultTableDataProvider;
061: import java.sql.SQLException;
062: import javax.faces.FacesException;
063: import javax.faces.component.html.HtmlPanelGrid;
064: import javax.sql.rowset.CachedRowSet;
065:
066: /**
067: * <p>Page bean that corresponds to a similarly named JSP page. This
068: * class contains component definitions (and initialization code) for
069: * all components that you have defined on this page, as well as
070: * lifecycle methods and event handlers where you may add behavior
071: * to respond to incoming events.</p>
072: */
073: public class Vehicles extends AbstractPageBean {
074: // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
075: private int __placeholder;
076:
077: /**
078: * <p>Automatically managed component initialization. <strong>WARNING:</strong>
079: * This method is automatically generated, so any user-specified code inserted
080: * here is subject to being replaced.</p>
081: */
082: private void _init() throws Exception {
083: ownerDataProvider
084: .setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.ownerRowSet}"));
085: }
086:
087: private Page page1 = new Page();
088:
089: public Page getPage1() {
090: return page1;
091: }
092:
093: public void setPage1(Page p) {
094: this .page1 = p;
095: }
096:
097: private Html html1 = new Html();
098:
099: public Html getHtml1() {
100: return html1;
101: }
102:
103: public void setHtml1(Html h) {
104: this .html1 = h;
105: }
106:
107: private Head head1 = new Head();
108:
109: public Head getHead1() {
110: return head1;
111: }
112:
113: public void setHead1(Head h) {
114: this .head1 = h;
115: }
116:
117: private Link link1 = new Link();
118:
119: public Link getLink1() {
120: return link1;
121: }
122:
123: public void setLink1(Link l) {
124: this .link1 = l;
125: }
126:
127: private Body body1 = new Body();
128:
129: public Body getBody1() {
130: return body1;
131: }
132:
133: public void setBody1(Body b) {
134: this .body1 = b;
135: }
136:
137: private Form form1 = new Form();
138:
139: public Form getForm1() {
140: return form1;
141: }
142:
143: public void setForm1(Form f) {
144: this .form1 = f;
145: }
146:
147: private HtmlPanelGrid content = new HtmlPanelGrid();
148:
149: public HtmlPanelGrid getContent() {
150: return content;
151: }
152:
153: public void setContent(HtmlPanelGrid hpg) {
154: this .content = hpg;
155: }
156:
157: private HtmlPanelGrid contentGrid = new HtmlPanelGrid();
158:
159: public HtmlPanelGrid getContentGrid() {
160: return contentGrid;
161: }
162:
163: public void setContentGrid(HtmlPanelGrid hpg) {
164: this .contentGrid = hpg;
165: }
166:
167: private HtmlPanelGrid messagePanel = new HtmlPanelGrid();
168:
169: public HtmlPanelGrid getMessagePanel() {
170: return messagePanel;
171: }
172:
173: public void setMessagePanel(HtmlPanelGrid hpg) {
174: this .messagePanel = hpg;
175: }
176:
177: private MessageGroup messageGroup1 = new MessageGroup();
178:
179: public MessageGroup getMessageGroup1() {
180: return messageGroup1;
181: }
182:
183: public void setMessageGroup1(MessageGroup mg) {
184: this .messageGroup1 = mg;
185: }
186:
187: private HtmlPanelGrid paddingPanel = new HtmlPanelGrid();
188:
189: public HtmlPanelGrid getPaddingPanel() {
190: return paddingPanel;
191: }
192:
193: public void setPaddingPanel(HtmlPanelGrid hpg) {
194: this .paddingPanel = hpg;
195: }
196:
197: private HtmlPanelGrid dataGrid = new HtmlPanelGrid();
198:
199: public HtmlPanelGrid getDataGrid() {
200: return dataGrid;
201: }
202:
203: public void setDataGrid(HtmlPanelGrid hpg) {
204: this .dataGrid = hpg;
205: }
206:
207: private Table vehicles = new Table();
208:
209: public Table getVehicles() {
210: return vehicles;
211: }
212:
213: public void setVehicles(Table t) {
214: this .vehicles = t;
215: }
216:
217: private TableRowGroup tableRowGroup1 = new TableRowGroup();
218:
219: public TableRowGroup getTableRowGroup1() {
220: return tableRowGroup1;
221: }
222:
223: public void setTableRowGroup1(TableRowGroup trg) {
224: this .tableRowGroup1 = trg;
225: }
226:
227: private CachedRowSetDataProvider ownerDataProvider = new CachedRowSetDataProvider();
228:
229: public CachedRowSetDataProvider getOwnerDataProvider() {
230: return ownerDataProvider;
231: }
232:
233: public void setOwnerDataProvider(CachedRowSetDataProvider crsdp) {
234: this .ownerDataProvider = crsdp;
235: }
236:
237: private TableColumn tableColumn1 = new TableColumn();
238:
239: public TableColumn getTableColumn1() {
240: return tableColumn1;
241: }
242:
243: public void setTableColumn1(TableColumn tc) {
244: this .tableColumn1 = tc;
245: }
246:
247: private StaticText staticText1 = new StaticText();
248:
249: public StaticText getStaticText1() {
250: return staticText1;
251: }
252:
253: public void setStaticText1(StaticText st) {
254: this .staticText1 = st;
255: }
256:
257: private TableColumn tableColumn2 = new TableColumn();
258:
259: public TableColumn getTableColumn2() {
260: return tableColumn2;
261: }
262:
263: public void setTableColumn2(TableColumn tc) {
264: this .tableColumn2 = tc;
265: }
266:
267: private StaticText staticText2 = new StaticText();
268:
269: public StaticText getStaticText2() {
270: return staticText2;
271: }
272:
273: public void setStaticText2(StaticText st) {
274: this .staticText2 = st;
275: }
276:
277: private TableColumn tableColumn3 = new TableColumn();
278:
279: public TableColumn getTableColumn3() {
280: return tableColumn3;
281: }
282:
283: public void setTableColumn3(TableColumn tc) {
284: this .tableColumn3 = tc;
285: }
286:
287: private StaticText staticText3 = new StaticText();
288:
289: public StaticText getStaticText3() {
290: return staticText3;
291: }
292:
293: public void setStaticText3(StaticText st) {
294: this .staticText3 = st;
295: }
296:
297: private TableColumn tableColumn4 = new TableColumn();
298:
299: public TableColumn getTableColumn4() {
300: return tableColumn4;
301: }
302:
303: public void setTableColumn4(TableColumn tc) {
304: this .tableColumn4 = tc;
305: }
306:
307: private StaticText staticText4 = new StaticText();
308:
309: public StaticText getStaticText4() {
310: return staticText4;
311: }
312:
313: public void setStaticText4(StaticText st) {
314: this .staticText4 = st;
315: }
316:
317: private TableColumn tableColumn5 = new TableColumn();
318:
319: public TableColumn getTableColumn5() {
320: return tableColumn5;
321: }
322:
323: public void setTableColumn5(TableColumn tc) {
324: this .tableColumn5 = tc;
325: }
326:
327: private StaticText staticText5 = new StaticText();
328:
329: public StaticText getStaticText5() {
330: return staticText5;
331: }
332:
333: public void setStaticText5(StaticText st) {
334: this .staticText5 = st;
335: }
336:
337: private TableColumn tableColumn6 = new TableColumn();
338:
339: public TableColumn getTableColumn6() {
340: return tableColumn6;
341: }
342:
343: public void setTableColumn6(TableColumn tc) {
344: this .tableColumn6 = tc;
345: }
346:
347: private Button delete = new Button();
348:
349: public Button getDelete() {
350: return delete;
351: }
352:
353: public void setDelete(Button b) {
354: this .delete = b;
355: }
356:
357: private Button add = new Button();
358:
359: public Button getAdd() {
360: return add;
361: }
362:
363: public void setAdd(Button b) {
364: this .add = b;
365: }
366:
367: // </editor-fold>
368:
369: /**
370: * <p>Construct a new Page bean instance.</p>
371: */
372: public Vehicles() {
373: }
374:
375: /**
376: * <p>Callback method that is called whenever a page is navigated to,
377: * either directly via a URL, or indirectly via page navigation.
378: * Customize this method to acquire resources that will be needed
379: * for event handlers and lifecycle methods, whether or not this
380: * page is performing post back processing.</p>
381: *
382: * <p>Note that, if the current request is a postback, the property
383: * values of the components do <strong>not</strong> represent any
384: * values submitted with this request. Instead, they represent the
385: * property values that were saved for this view when it was rendered.</p>
386: */
387: @Override
388: public void init() {
389: // Perform initializations inherited from our superclass
390: super .init();
391: // Perform application initialization that must complete
392: // *before* managed components are initialized
393: // TODO - add your own initialiation code here
394:
395: // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
396: // Initialize automatically managed components
397: // *Note* - this logic should NOT be modified
398: try {
399: _init();
400: } catch (Exception e) {
401: log("Vehicles Initialization Failure", e);
402: throw e instanceof FacesException ? (FacesException) e
403: : new FacesException(e);
404: }
405:
406: // </editor-fold>
407: // Perform application initialization that must complete
408: // *after* managed components are initialized
409: // TODO - add your own initialization code here
410: // set the logged in user as the owner
411: try {
412: getSessionBean1().getOwnerRowSet().release();
413: getSessionBean1().getOwnerRowSet().setObject(1,
414: getSessionBean1().getLoggedInUserId());
415: this .ownerDataProvider.refresh();
416: } catch (SQLException sqe) {
417: error(sqe.getMessage());
418: }
419: }
420:
421: /**
422: * <p>Callback method that is called after the component tree has been
423: * restored, but before any event processing takes place. This method
424: * will <strong>only</strong> be called on a postback request that
425: * is processing a form submit. Customize this method to allocate
426: * resources that will be required in your event handlers.</p>
427: */
428: @Override
429: public void preprocess() {
430: }
431:
432: /**
433: * <p>Callback method that is called just before rendering takes place.
434: * This method will <strong>only</strong> be called for the page that
435: * will actually be rendered (and not, for example, on a page that
436: * handled a postback and then navigated to a different page). Customize
437: * this method to allocate resources that will be required for rendering
438: * this page.</p>
439: */
440: @Override
441: public void prerender() {
442: }
443:
444: /**
445: * <p>Callback method that is called after rendering is completed for
446: * this request, if <code>init()</code> was called (regardless of whether
447: * or not this was the page that was actually rendered). Customize this
448: * method to release resources acquired in the <code>init()</code>,
449: * <code>preprocess()</code>, or <code>prerender()</code> methods (or
450: * acquired during execution of an event handler).</p>
451: */
452: @Override
453: public void destroy() {
454: ownerDataProvider.close();
455: }
456:
457: /**
458: * <p>Return a reference to the scoped data bean.</p>
459: */
460: protected ApplicationBean1 getApplicationBean1() {
461: return (ApplicationBean1) getBean("ApplicationBean1");
462: }
463:
464: /**
465: * <p>Return a reference to the scoped data bean.</p>
466: */
467: protected SessionBean1 getSessionBean1() {
468: return (SessionBean1) getBean("SessionBean1");
469: }
470:
471: /**
472: * <p>Return a reference to the scoped data bean.</p>
473: */
474: protected RequestBean1 getRequestBean1() {
475: return (RequestBean1) getBean("RequestBean1");
476: }
477:
478: public String delete_action() {
479: // TODO: Process the action. Return value is a navigation
480: // case name where null will return to the same page.
481:
482: // delete the entry from owner table
483: String stateId = (String) getValue("#{currentRow.value['owner.stateid']}");
484: String licensePlate = (String) getValue("#{currentRow.value['owner.licenseplate']}");
485: Integer employeeId = (Integer) getValue("#{currentRow.value['owner.employeeid']}");
486: try {
487: RowKey rowKey = this .ownerDataProvider.findFirst(
488: new String[] { "owner.stateid",
489: "owner.licenseplate", "owner.employeeid" },
490: new Object[] { stateId, licensePlate, employeeId });
491: if (rowKey != null) {
492: this .ownerDataProvider.removeRow(rowKey);
493: this .ownerDataProvider.commitChanges();
494: } else {
495: error("Could not delete vehicle.");
496: }
497: } catch (Exception ex) {
498: log(ex.getMessage(), ex);
499: error(ex.getMessage());
500: }
501:
502: // TODO: Cleanup the vehicle if nobody owns it.
503: try {
504: CachedRowSet ownerRowSet = new CachedRowSetXImpl();
505: ownerRowSet
506: .setDataSourceName("java:comp/env/jdbc/VIR_ApacheDerby");
507: ownerRowSet.setTableName("OWNER");
508: ownerRowSet.setCommand("SELECT * FROM VIR.OWNER "
509: + "WHERE " + "VIR.OWNER.STATEID=" + "'" + stateId
510: + "' " + "AND VIR.OWNER.LICENSEPLATE=" + "'"
511: + licensePlate + "' ");
512: ownerRowSet.execute();
513: if (!ownerRowSet.next()) {
514: // No other owner - delete the vehicle
515: CachedRowSet vehicleRowSet = new CachedRowSetXImpl();
516: vehicleRowSet
517: .setDataSourceName("java:comp/env/jdbc/VIR_ApacheDerby");
518: vehicleRowSet.setTableName("VEHICLE");
519: vehicleRowSet.setCommand("SELECT * FROM VIR.VEHICLE");
520: CachedRowSetDataProvider vehicleDataProvider = new CachedRowSetDataProvider();
521: vehicleDataProvider.setCachedRowSet(vehicleRowSet);
522: RowKey rowKey = vehicleDataProvider.findFirst(
523: new String[] { "vehicle.stateid",
524: "vehicle.licenseplate" }, new Object[] {
525: stateId, licensePlate });
526: if (rowKey != null) {
527: vehicleDataProvider.removeRow(rowKey);
528: vehicleDataProvider.commitChanges();
529: getSessionBean1().getVehicleRowSet().release();
530: } else {
531: error("Could not delete vehicle.");
532: }
533: }
534: } catch (Exception ex) {
535: log(ex.getMessage(), ex);
536: error(ex.getMessage());
537: }
538: return null;
539: }
540:
541: public String add_action() {
542: // TODO: Process the action. Return value is a navigation
543: // case name where null will return to the same page.
544: return "addVehicle";
545: }
546: }
|