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.impl.CachedRowSetDataProvider;
045: import com.sun.rave.web.ui.appbase.AbstractPageBean;
046: import com.sun.webui.jsf.component.Body;
047: import com.sun.webui.jsf.component.Button;
048: import com.sun.webui.jsf.component.DropDown;
049: import com.sun.webui.jsf.component.Form;
050: import com.sun.webui.jsf.component.Head;
051: import com.sun.webui.jsf.component.Html;
052: import com.sun.webui.jsf.component.Label;
053: import com.sun.webui.jsf.component.Link;
054: import com.sun.webui.jsf.component.Message;
055: import com.sun.webui.jsf.component.MessageGroup;
056: import com.sun.webui.jsf.component.Page;
057: import com.sun.webui.jsf.component.TextField;
058: import com.sun.webui.jsf.model.SingleSelectOptionsList;
059: import java.sql.SQLException;
060: import javax.faces.FacesException;
061: import javax.faces.component.html.HtmlPanelGrid;
062: import javax.sql.rowset.CachedRowSet;
063:
064: /**
065: * <p>Page bean that corresponds to a similarly named JSP page. This
066: * class contains component definitions (and initialization code) for
067: * all components that you have defined on this page, as well as
068: * lifecycle methods and event handlers where you may add behavior
069: * to respond to incoming events.</p>
070: */
071: public class FindVehicle extends AbstractPageBean {
072: // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
073: private int __placeholder;
074:
075: /**
076: * <p>Automatically managed component initialization. <strong>WARNING:</strong>
077: * This method is automatically generated, so any user-specified code inserted
078: * here is subject to being replaced.</p>
079: */
080: private void _init() throws Exception {
081: vehicleDataProvider
082: .setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.vehicleRowSet}"));
083: stateDataProvider
084: .setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.stateRowSet}"));
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 HtmlPanelGrid paddingPanel = new HtmlPanelGrid();
178:
179: public HtmlPanelGrid getPaddingPanel() {
180: return paddingPanel;
181: }
182:
183: public void setPaddingPanel(HtmlPanelGrid hpg) {
184: this .paddingPanel = hpg;
185: }
186:
187: private HtmlPanelGrid dataGrid = new HtmlPanelGrid();
188:
189: public HtmlPanelGrid getDataGrid() {
190: return dataGrid;
191: }
192:
193: public void setDataGrid(HtmlPanelGrid hpg) {
194: this .dataGrid = hpg;
195: }
196:
197: private MessageGroup messageGroup1 = new MessageGroup();
198:
199: public MessageGroup getMessageGroup1() {
200: return messageGroup1;
201: }
202:
203: public void setMessageGroup1(MessageGroup mg) {
204: this .messageGroup1 = mg;
205: }
206:
207: private Label label1 = new Label();
208:
209: public Label getLabel1() {
210: return label1;
211: }
212:
213: public void setLabel1(Label l) {
214: this .label1 = l;
215: }
216:
217: private Label label2 = new Label();
218:
219: public Label getLabel2() {
220: return label2;
221: }
222:
223: public void setLabel2(Label l) {
224: this .label2 = l;
225: }
226:
227: private Label label3 = new Label();
228:
229: public Label getLabel3() {
230: return label3;
231: }
232:
233: public void setLabel3(Label l) {
234: this .label3 = l;
235: }
236:
237: private Label label4 = new Label();
238:
239: public Label getLabel4() {
240: return label4;
241: }
242:
243: public void setLabel4(Label l) {
244: this .label4 = l;
245: }
246:
247: private Label label5 = new Label();
248:
249: public Label getLabel5() {
250: return label5;
251: }
252:
253: public void setLabel5(Label l) {
254: this .label5 = l;
255: }
256:
257: private DropDown state = new DropDown();
258:
259: public DropDown getState() {
260: return state;
261: }
262:
263: public void setState(DropDown dd) {
264: this .state = dd;
265: }
266:
267: private Message message1 = new Message();
268:
269: public Message getMessage1() {
270: return message1;
271: }
272:
273: public void setMessage1(Message m) {
274: this .message1 = m;
275: }
276:
277: private TextField licensePlate = new TextField();
278:
279: public TextField getLicensePlate() {
280: return licensePlate;
281: }
282:
283: public void setLicensePlate(TextField tf) {
284: this .licensePlate = tf;
285: }
286:
287: private Message message2 = new Message();
288:
289: public Message getMessage2() {
290: return message2;
291: }
292:
293: public void setMessage2(Message m) {
294: this .message2 = m;
295: }
296:
297: private TextField make = new TextField();
298:
299: public TextField getMake() {
300: return make;
301: }
302:
303: public void setMake(TextField tf) {
304: this .make = tf;
305: }
306:
307: private Message message3 = new Message();
308:
309: public Message getMessage3() {
310: return message3;
311: }
312:
313: public void setMessage3(Message m) {
314: this .message3 = m;
315: }
316:
317: private TextField model = new TextField();
318:
319: public TextField getModel() {
320: return model;
321: }
322:
323: public void setModel(TextField tf) {
324: this .model = tf;
325: }
326:
327: private Message message4 = new Message();
328:
329: public Message getMessage4() {
330: return message4;
331: }
332:
333: public void setMessage4(Message m) {
334: this .message4 = m;
335: }
336:
337: private TextField color = new TextField();
338:
339: public TextField getColor() {
340: return color;
341: }
342:
343: public void setColor(TextField tf) {
344: this .color = tf;
345: }
346:
347: private Message message5 = new Message();
348:
349: public Message getMessage5() {
350: return message5;
351: }
352:
353: public void setMessage5(Message m) {
354: this .message5 = m;
355: }
356:
357: private Button searchButton = new Button();
358:
359: public Button getSearchButton() {
360: return searchButton;
361: }
362:
363: public void setSearchButton(Button b) {
364: this .searchButton = b;
365: }
366:
367: private CachedRowSetDataProvider vehicleDataProvider = new CachedRowSetDataProvider();
368:
369: public CachedRowSetDataProvider getVehicleDataProvider() {
370: return vehicleDataProvider;
371: }
372:
373: public void setVehicleDataProvider(CachedRowSetDataProvider crsdp) {
374: this .vehicleDataProvider = crsdp;
375: }
376:
377: private CachedRowSetDataProvider stateDataProvider = new CachedRowSetDataProvider();
378:
379: public CachedRowSetDataProvider getStateDataProvider() {
380: return stateDataProvider;
381: }
382:
383: public void setStateDataProvider(CachedRowSetDataProvider crsdp) {
384: this .stateDataProvider = crsdp;
385: }
386:
387: // </editor-fold>
388:
389: /**
390: * <p>Construct a new Page bean instance.</p>
391: */
392: public FindVehicle() {
393: }
394:
395: /**
396: * <p>Callback method that is called whenever a page is navigated to,
397: * either directly via a URL, or indirectly via page navigation.
398: * Customize this method to acquire resources that will be needed
399: * for event handlers and lifecycle methods, whether or not this
400: * page is performing post back processing.</p>
401: *
402: * <p>Note that, if the current request is a postback, the property
403: * values of the components do <strong>not</strong> represent any
404: * values submitted with this request. Instead, they represent the
405: * property values that were saved for this view when it was rendered.</p>
406: */
407: public void init() {
408: // Perform initializations inherited from our superclass
409: super .init();
410: // Perform application initialization that must complete
411: // *before* managed components are initialized
412: // TODO - add your own initialiation code here
413:
414: // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
415: // Initialize automatically managed components
416: // *Note* - this logic should NOT be modified
417: try {
418: _init();
419: } catch (Exception e) {
420: log("FindVehicle Initialization Failure", e);
421: throw e instanceof FacesException ? (FacesException) e
422: : new FacesException(e);
423: }
424:
425: // </editor-fold>
426: // Perform application initialization that must complete
427: // *after* managed components are initialized
428: // TODO - add your own initialization code here
429: }
430:
431: /**
432: * <p>Callback method that is called after the component tree has been
433: * restored, but before any event processing takes place. This method
434: * will <strong>only</strong> be called on a postback request that
435: * is processing a form submit. Customize this method to allocate
436: * resources that will be required in your event handlers.</p>
437: */
438: public void preprocess() {
439: }
440:
441: /**
442: * <p>Callback method that is called just before rendering takes place.
443: * This method will <strong>only</strong> be called for the page that
444: * will actually be rendered (and not, for example, on a page that
445: * handled a postback and then navigated to a different page). Customize
446: * this method to allocate resources that will be required for rendering
447: * this page.</p>
448: */
449: public void prerender() {
450: }
451:
452: /**
453: * <p>Callback method that is called after rendering is completed for
454: * this request, if <code>init()</code> was called (regardless of whether
455: * or not this was the page that was actually rendered). Customize this
456: * method to release resources acquired in the <code>init()</code>,
457: * <code>preprocess()</code>, or <code>prerender()</code> methods (or
458: * acquired during execution of an event handler).</p>
459: */
460: public void destroy() {
461: vehicleDataProvider.close();
462: stateDataProvider.close();
463: }
464:
465: /**
466: * <p>Return a reference to the scoped data bean.</p>
467: */
468: protected ApplicationBean1 getApplicationBean1() {
469: return (ApplicationBean1) getBean("ApplicationBean1");
470: }
471:
472: /**
473: * <p>Return a reference to the scoped data bean.</p>
474: */
475: protected SessionBean1 getSessionBean1() {
476: return (SessionBean1) getBean("SessionBean1");
477: }
478:
479: /**
480: * <p>Return a reference to the scoped data bean.</p>
481: */
482: protected RequestBean1 getRequestBean1() {
483: return (RequestBean1) getBean("RequestBean1");
484: }
485:
486: public String searchButton_action() {
487: // TODO: Process the action. Return value is a navigation
488: // case name where null will return to the same page.
489: String result = null;
490: String stateId = (String) this .state.getSelected();
491:
492: if (stateId == null) {
493: error("Select a state");
494: result = null;
495: }
496:
497: if (stateId.equals(STATE_WILD_CARD)) {
498: stateId = SQL_WILD_CARD;
499: }
500:
501: String theLicensePlate = transformUserInput((String) this .licensePlate
502: .getText());
503: String theMake = transformUserInput((String) this .make
504: .getText());
505: String theModel = transformUserInput((String) this .model
506: .getText());
507: String theColor = transformUserInput((String) this .color
508: .getText());
509:
510: try {
511: CachedRowSet findVehicleRowset = getSessionBean1()
512: .getVehicleRowSet();
513: findVehicleRowset.setObject(1, stateId);
514: findVehicleRowset.setObject(2, theLicensePlate);
515: findVehicleRowset.setObject(3, theMake);
516: findVehicleRowset.setObject(4, theModel);
517: findVehicleRowset.setObject(5, theColor);
518:
519: findVehicleRowset.execute();
520: findVehicleRowset.last();
521: int currentRow = findVehicleRowset.getRow();
522: if (currentRow == 0) {
523: error("No vehicles found!");
524: result = null;
525: } else if (currentRow == 1) {
526: result = "report";
527: } else {
528: result = "select";
529: }
530: } catch (SQLException sqle) {
531: error(sqle.getMessage());
532: }
533:
534: return result;
535: }
536:
537: private String transformUserInput(String input) {
538: String result = null;
539: if (result == null || result.equals("")) {
540: result = SQL_WILD_CARD;
541: } else {
542: result = result.trim();
543: if (result.length() > 0
544: && result.indexOf(SQL_WILD_CARD) == -1) {
545: result = SQL_WILD_CARD + result + SQL_WILD_CARD;
546: }
547: }
548: return result;
549: }
550:
551: private static String SQL_WILD_CARD = "%";
552: private static String STATE_WILD_CARD = "xx";
553: }
|