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.webui.jsf.component.Body;
048: import com.sun.webui.jsf.component.Button;
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.PasswordField;
058: import com.sun.webui.jsf.component.StaticText;
059: import com.sun.webui.jsf.component.TextField;
060: import javax.faces.FacesException;
061: import javax.faces.application.FacesMessage;
062: import javax.faces.component.UIComponent;
063: import javax.faces.component.html.HtmlPanelGrid;
064: import javax.faces.context.FacesContext;
065: import javax.faces.validator.LengthValidator;
066: import javax.faces.validator.ValidatorException;
067:
068: /**
069: * <p>Page bean that corresponds to a similarly named JSP page. This
070: * class contains component definitions (and initialization code) for
071: * all components that you have defined on this page, as well as
072: * lifecycle methods and event handlers where you may add behavior
073: * to respond to incoming events.</p>
074: */
075: public class Profile extends AbstractPageBean {
076: // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
077: private int __placeholder;
078:
079: /**
080: * <p>Automatically managed component initialization. <strong>WARNING:</strong>
081: * This method is automatically generated, so any user-specified code inserted
082: * here is subject to being replaced.</p>
083: */
084: private void _init() throws Exception {
085: employeeDataProvider
086: .setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.employeeRowSet}"));
087: passwordDataProvider
088: .setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.passwordRowSet}"));
089: passwordLengthValidator.setMaximum(10);
090: passwordLengthValidator.setMinimum(6);
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 content = new HtmlPanelGrid();
154:
155: public HtmlPanelGrid getContent() {
156: return content;
157: }
158:
159: public void setContent(HtmlPanelGrid hpg) {
160: this .content = hpg;
161: }
162:
163: private HtmlPanelGrid contentGrid = new HtmlPanelGrid();
164:
165: public HtmlPanelGrid getContentGrid() {
166: return contentGrid;
167: }
168:
169: public void setContentGrid(HtmlPanelGrid hpg) {
170: this .contentGrid = hpg;
171: }
172:
173: private HtmlPanelGrid messageGrid = new HtmlPanelGrid();
174:
175: public HtmlPanelGrid getMessageGrid() {
176: return messageGrid;
177: }
178:
179: public void setMessageGrid(HtmlPanelGrid hpg) {
180: this .messageGrid = hpg;
181: }
182:
183: private HtmlPanelGrid paddingPanel = new HtmlPanelGrid();
184:
185: public HtmlPanelGrid getPaddingPanel() {
186: return paddingPanel;
187: }
188:
189: public void setPaddingPanel(HtmlPanelGrid hpg) {
190: this .paddingPanel = hpg;
191: }
192:
193: private HtmlPanelGrid dataGrid = new HtmlPanelGrid();
194:
195: public HtmlPanelGrid getDataGrid() {
196: return dataGrid;
197: }
198:
199: public void setDataGrid(HtmlPanelGrid hpg) {
200: this .dataGrid = hpg;
201: }
202:
203: private MessageGroup messageGroup1 = new MessageGroup();
204:
205: public MessageGroup getMessageGroup1() {
206: return messageGroup1;
207: }
208:
209: public void setMessageGroup1(MessageGroup mg) {
210: this .messageGroup1 = mg;
211: }
212:
213: private Label label1 = new Label();
214:
215: public Label getLabel1() {
216: return label1;
217: }
218:
219: public void setLabel1(Label l) {
220: this .label1 = l;
221: }
222:
223: private Message message1 = new Message();
224:
225: public Message getMessage1() {
226: return message1;
227: }
228:
229: public void setMessage1(Message m) {
230: this .message1 = m;
231: }
232:
233: private Label label2 = new Label();
234:
235: public Label getLabel2() {
236: return label2;
237: }
238:
239: public void setLabel2(Label l) {
240: this .label2 = l;
241: }
242:
243: private TextField firstName = new TextField();
244:
245: public TextField getFirstName() {
246: return firstName;
247: }
248:
249: public void setFirstName(TextField tf) {
250: this .firstName = tf;
251: }
252:
253: private Message message2 = new Message();
254:
255: public Message getMessage2() {
256: return message2;
257: }
258:
259: public void setMessage2(Message m) {
260: this .message2 = m;
261: }
262:
263: private Label label3 = new Label();
264:
265: public Label getLabel3() {
266: return label3;
267: }
268:
269: public void setLabel3(Label l) {
270: this .label3 = l;
271: }
272:
273: private TextField lastName = new TextField();
274:
275: public TextField getLastName() {
276: return lastName;
277: }
278:
279: public void setLastName(TextField tf) {
280: this .lastName = tf;
281: }
282:
283: private Message message3 = new Message();
284:
285: public Message getMessage3() {
286: return message3;
287: }
288:
289: public void setMessage3(Message m) {
290: this .message3 = m;
291: }
292:
293: private Label label4 = new Label();
294:
295: public Label getLabel4() {
296: return label4;
297: }
298:
299: public void setLabel4(Label l) {
300: this .label4 = l;
301: }
302:
303: private TextField emailAddress = new TextField();
304:
305: public TextField getEmailAddress() {
306: return emailAddress;
307: }
308:
309: public void setEmailAddress(TextField tf) {
310: this .emailAddress = tf;
311: }
312:
313: private Message message4 = new Message();
314:
315: public Message getMessage4() {
316: return message4;
317: }
318:
319: public void setMessage4(Message m) {
320: this .message4 = m;
321: }
322:
323: private Label label5 = new Label();
324:
325: public Label getLabel5() {
326: return label5;
327: }
328:
329: public void setLabel5(Label l) {
330: this .label5 = l;
331: }
332:
333: private PasswordField newPassword = new PasswordField();
334:
335: public PasswordField getNewPassword() {
336: return newPassword;
337: }
338:
339: public void setNewPassword(PasswordField pf) {
340: this .newPassword = pf;
341: }
342:
343: private Message message5 = new Message();
344:
345: public Message getMessage5() {
346: return message5;
347: }
348:
349: public void setMessage5(Message m) {
350: this .message5 = m;
351: }
352:
353: private Label label6 = new Label();
354:
355: public Label getLabel6() {
356: return label6;
357: }
358:
359: public void setLabel6(Label l) {
360: this .label6 = l;
361: }
362:
363: private PasswordField retypeNewPassword = new PasswordField();
364:
365: public PasswordField getRetypeNewPassword() {
366: return retypeNewPassword;
367: }
368:
369: public void setRetypeNewPassword(PasswordField pf) {
370: this .retypeNewPassword = pf;
371: }
372:
373: private Message message6 = new Message();
374:
375: public Message getMessage6() {
376: return message6;
377: }
378:
379: public void setMessage6(Message m) {
380: this .message6 = m;
381: }
382:
383: private StaticText userId = new StaticText();
384:
385: public StaticText getUserId() {
386: return userId;
387: }
388:
389: public void setUserId(StaticText st) {
390: this .userId = st;
391: }
392:
393: private CachedRowSetDataProvider employeeDataProvider = new CachedRowSetDataProvider();
394:
395: public CachedRowSetDataProvider getEmployeeDataProvider() {
396: return employeeDataProvider;
397: }
398:
399: public void setEmployeeDataProvider(CachedRowSetDataProvider crsdp) {
400: this .employeeDataProvider = crsdp;
401: }
402:
403: private CachedRowSetDataProvider passwordDataProvider = new CachedRowSetDataProvider();
404:
405: public CachedRowSetDataProvider getPasswordDataProvider() {
406: return passwordDataProvider;
407: }
408:
409: public void setPasswordDataProvider(CachedRowSetDataProvider crsdp) {
410: this .passwordDataProvider = crsdp;
411: }
412:
413: private Label label7 = new Label();
414:
415: public Label getLabel7() {
416: return label7;
417: }
418:
419: public void setLabel7(Label l) {
420: this .label7 = l;
421: }
422:
423: private PasswordField currentPassword = new PasswordField();
424:
425: public PasswordField getCurrentPassword() {
426: return currentPassword;
427: }
428:
429: public void setCurrentPassword(PasswordField pf) {
430: this .currentPassword = pf;
431: }
432:
433: private Message message7 = new Message();
434:
435: public Message getMessage7() {
436: return message7;
437: }
438:
439: public void setMessage7(Message m) {
440: this .message7 = m;
441: }
442:
443: private Button update = new Button();
444:
445: public Button getUpdate() {
446: return update;
447: }
448:
449: public void setUpdate(Button b) {
450: this .update = b;
451: }
452:
453: private LengthValidator passwordLengthValidator = new LengthValidator();
454:
455: public LengthValidator getPasswordLengthValidator() {
456: return passwordLengthValidator;
457: }
458:
459: public void setPasswordLengthValidator(LengthValidator lv) {
460: this .passwordLengthValidator = lv;
461: }
462:
463: // </editor-fold>
464:
465: /**
466: * <p>Construct a new Page bean instance.</p>
467: */
468: public Profile() {
469: }
470:
471: /**
472: * <p>Callback method that is called whenever a page is navigated to,
473: * either directly via a URL, or indirectly via page navigation.
474: * Customize this method to acquire resources that will be needed
475: * for event handlers and lifecycle methods, whether or not this
476: * page is performing post back processing.</p>
477: *
478: * <p>Note that, if the current request is a postback, the property
479: * values of the components do <strong>not</strong> represent any
480: * values submitted with this request. Instead, they represent the
481: * property values that were saved for this view when it was rendered.</p>
482: */
483: @Override
484: public void init() {
485: // Perform initializations inherited from our superclass
486: super .init();
487: // Perform application initialization that must complete
488: // *before* managed components are initialized
489: // TODO - add your own initialiation code here
490:
491: // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
492: // Initialize automatically managed components
493: // *Note* - this logic should NOT be modified
494: try {
495: _init();
496: } catch (Exception e) {
497: log("Profile Initialization Failure", e);
498: throw e instanceof FacesException ? (FacesException) e
499: : new FacesException(e);
500: }
501:
502: // </editor-fold>
503: // Perform application initialization that must complete
504: // *after* managed components are initialized
505: // TODO - add your own initialization code here
506: }
507:
508: /**
509: * <p>Callback method that is called after the component tree has been
510: * restored, but before any event processing takes place. This method
511: * will <strong>only</strong> be called on a postback request that
512: * is processing a form submit. Customize this method to allocate
513: * resources that will be required in your event handlers.</p>
514: */
515: @Override
516: public void preprocess() {
517: }
518:
519: /**
520: * <p>Callback method that is called just before rendering takes place.
521: * This method will <strong>only</strong> be called for the page that
522: * will actually be rendered (and not, for example, on a page that
523: * handled a postback and then navigated to a different page). Customize
524: * this method to allocate resources that will be required for rendering
525: * this page.</p>
526: */
527: @Override
528: public void prerender() {
529: this .currentPassword.setText(null);
530: this .newPassword.setText(null);
531: this .retypeNewPassword.setText(null);
532:
533: RowKey rowKey = getPasswordDataProvider().findFirst(
534: new String[] { "password.id" },
535: new Object[] { getSessionBean1().getLoggedInUserId() });
536: getPasswordDataProvider().setCursorRow(rowKey);
537:
538: rowKey = getEmployeeDataProvider().findFirst(
539: new String[] { "employee.id" },
540: new Object[] { getSessionBean1().getLoggedInUserId() });
541: getEmployeeDataProvider().setCursorRow(rowKey);
542: }
543:
544: /**
545: * <p>Callback method that is called after rendering is completed for
546: * this request, if <code>init()</code> was called (regardless of whether
547: * or not this was the page that was actually rendered). Customize this
548: * method to release resources acquired in the <code>init()</code>,
549: * <code>preprocess()</code>, or <code>prerender()</code> methods (or
550: * acquired during execution of an event handler).</p>
551: */
552: @Override
553: public void destroy() {
554: employeeDataProvider.close();
555: passwordDataProvider.close();
556: }
557:
558: /**
559: * <p>Return a reference to the scoped data bean.</p>
560: */
561: protected ApplicationBean1 getApplicationBean1() {
562: return (ApplicationBean1) getBean("ApplicationBean1");
563: }
564:
565: /**
566: * <p>Return a reference to the scoped data bean.</p>
567: */
568: protected SessionBean1 getSessionBean1() {
569: return (SessionBean1) getBean("SessionBean1");
570: }
571:
572: /**
573: * <p>Return a reference to the scoped data bean.</p>
574: */
575: protected RequestBean1 getRequestBean1() {
576: return (RequestBean1) getBean("RequestBean1");
577: }
578:
579: public void emailAddress_validate(FacesContext context,
580: UIComponent component, Object value) {
581: String email = (String) value;
582: if (email.indexOf("@") == -1 || email.startsWith("@")
583: || email.endsWith("@")) {
584: throw new ValidatorException(new FacesMessage(
585: "Enter a valid email address."));
586: }
587: }
588:
589: public String update_action() {
590: // TODO: Process the action. Return value is a navigation
591: // case name where null will return to the same page.
592:
593: String theFirstName = (String) this .firstName.getText();
594: String theLastName = (String) this .lastName.getText();
595: String theEmailAddress = (String) this .emailAddress.getText();
596: RowKey rowKey;
597: // check if new password is a valid password and equals retyped password.
598: String theNewPassword = (String) this .newPassword.getText();
599: String theRetypeNewPassword = (String) this .retypeNewPassword
600: .getText();
601: if (theRetypeNewPassword == null
602: || !theNewPassword.equals(theRetypeNewPassword.trim())) {
603: error("New password and retyped password do not match.");
604: return null;
605: }
606: String theCurrentPassword = (String) this .currentPassword
607: .getText();
608: rowKey = getPasswordDataProvider().findFirst(
609: new String[] { "password.id", "password.password" },
610: new Object[] { getSessionBean1().getLoggedInUserId(),
611: theCurrentPassword });
612: if (rowKey == null) {
613: error("Could not login with current password.");
614: return null;
615: }
616:
617: getPasswordDataProvider().setValue("password.password", rowKey,
618: theNewPassword);
619: getPasswordDataProvider().commitChanges();
620:
621: getEmployeeDataProvider().commitChanges();
622: getSessionBean1().setLoggedInUserName(
623: getEmployeeDataProvider()
624: .getValue("employee.firstname")
625: + " "
626: + getEmployeeDataProvider().getValue(
627: "employee.lastname"));
628:
629: return "vehicles";
630: }
631: }
|