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.TextField;
059: import javax.faces.FacesException;
060: import javax.faces.component.html.HtmlPanelGrid;
061: import javax.faces.convert.IntegerConverter;
062:
063: /**
064: * <p>Page bean that corresponds to a similarly named JSP page. This
065: * class contains component definitions (and initialization code) for
066: * all components that you have defined on this page, as well as
067: * lifecycle methods and event handlers where you may add behavior
068: * to respond to incoming events.</p>
069: */
070: public class Login extends AbstractPageBean {
071: // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
072: private int __placeholder;
073:
074: /**
075: * <p>Automatically managed component initialization. <strong>WARNING:</strong>
076: * This method is automatically generated, so any user-specified code inserted
077: * here is subject to being replaced.</p>
078: */
079: private void _init() throws Exception {
080: passwordDataProvider
081: .setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.passwordRowSet}"));
082: employeeDataProvider
083: .setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.employeeRowSet}"));
084: }
085:
086: private Page page1 = new Page();
087:
088: public Page getPage1() {
089: return page1;
090: }
091:
092: public void setPage1(Page p) {
093: this .page1 = p;
094: }
095:
096: private Html html1 = new Html();
097:
098: public Html getHtml1() {
099: return html1;
100: }
101:
102: public void setHtml1(Html h) {
103: this .html1 = h;
104: }
105:
106: private Head head1 = new Head();
107:
108: public Head getHead1() {
109: return head1;
110: }
111:
112: public void setHead1(Head h) {
113: this .head1 = h;
114: }
115:
116: private Link link1 = new Link();
117:
118: public Link getLink1() {
119: return link1;
120: }
121:
122: public void setLink1(Link l) {
123: this .link1 = l;
124: }
125:
126: private Body body1 = new Body();
127:
128: public Body getBody1() {
129: return body1;
130: }
131:
132: public void setBody1(Body b) {
133: this .body1 = b;
134: }
135:
136: private Form form1 = new Form();
137:
138: public Form getForm1() {
139: return form1;
140: }
141:
142: public void setForm1(Form f) {
143: this .form1 = f;
144: }
145:
146: private HtmlPanelGrid content = new HtmlPanelGrid();
147:
148: public HtmlPanelGrid getContent() {
149: return content;
150: }
151:
152: public void setContent(HtmlPanelGrid hpg) {
153: this .content = hpg;
154: }
155:
156: private HtmlPanelGrid contentGrid = new HtmlPanelGrid();
157:
158: public HtmlPanelGrid getContentGrid() {
159: return contentGrid;
160: }
161:
162: public void setContentGrid(HtmlPanelGrid hpg) {
163: this .contentGrid = hpg;
164: }
165:
166: private MessageGroup messageGroup1 = new MessageGroup();
167:
168: public MessageGroup getMessageGroup1() {
169: return messageGroup1;
170: }
171:
172: public void setMessageGroup1(MessageGroup mg) {
173: this .messageGroup1 = mg;
174: }
175:
176: private HtmlPanelGrid messagePanel = new HtmlPanelGrid();
177:
178: public HtmlPanelGrid getMessagePanel() {
179: return messagePanel;
180: }
181:
182: public void setMessagePanel(HtmlPanelGrid hpg) {
183: this .messagePanel = hpg;
184: }
185:
186: private HtmlPanelGrid paddingPanel = new HtmlPanelGrid();
187:
188: public HtmlPanelGrid getPaddingPanel() {
189: return paddingPanel;
190: }
191:
192: public void setPaddingPanel(HtmlPanelGrid hpg) {
193: this .paddingPanel = hpg;
194: }
195:
196: private HtmlPanelGrid dataGrid = new HtmlPanelGrid();
197:
198: public HtmlPanelGrid getDataGrid() {
199: return dataGrid;
200: }
201:
202: public void setDataGrid(HtmlPanelGrid hpg) {
203: this .dataGrid = hpg;
204: }
205:
206: private HtmlPanelGrid commandGrid = new HtmlPanelGrid();
207:
208: public HtmlPanelGrid getCommandGrid() {
209: return commandGrid;
210: }
211:
212: public void setCommandGrid(HtmlPanelGrid hpg) {
213: this .commandGrid = hpg;
214: }
215:
216: private Label label1 = new Label();
217:
218: public Label getLabel1() {
219: return label1;
220: }
221:
222: public void setLabel1(Label l) {
223: this .label1 = l;
224: }
225:
226: private Label label2 = new Label();
227:
228: public Label getLabel2() {
229: return label2;
230: }
231:
232: public void setLabel2(Label l) {
233: this .label2 = l;
234: }
235:
236: private TextField userId = new TextField();
237:
238: public TextField getUserId() {
239: return userId;
240: }
241:
242: public void setUserId(TextField tf) {
243: this .userId = tf;
244: }
245:
246: private PasswordField password = new PasswordField();
247:
248: public PasswordField getPassword() {
249: return password;
250: }
251:
252: public void setPassword(PasswordField pf) {
253: this .password = pf;
254: }
255:
256: private Message message1 = new Message();
257:
258: public Message getMessage1() {
259: return message1;
260: }
261:
262: public void setMessage1(Message m) {
263: this .message1 = m;
264: }
265:
266: private Message message2 = new Message();
267:
268: public Message getMessage2() {
269: return message2;
270: }
271:
272: public void setMessage2(Message m) {
273: this .message2 = m;
274: }
275:
276: private Button login = new Button();
277:
278: public Button getLogin() {
279: return login;
280: }
281:
282: public void setLogin(Button b) {
283: this .login = b;
284: }
285:
286: private Button register = new Button();
287:
288: public Button getRegister() {
289: return register;
290: }
291:
292: public void setRegister(Button b) {
293: this .register = b;
294: }
295:
296: private IntegerConverter integerConverter1 = new IntegerConverter();
297:
298: public IntegerConverter getIntegerConverter1() {
299: return integerConverter1;
300: }
301:
302: public void setIntegerConverter1(IntegerConverter ic) {
303: this .integerConverter1 = ic;
304: }
305:
306: private CachedRowSetDataProvider passwordDataProvider = new CachedRowSetDataProvider();
307:
308: public CachedRowSetDataProvider getPasswordDataProvider() {
309: return passwordDataProvider;
310: }
311:
312: public void setPasswordDataProvider(CachedRowSetDataProvider crsdp) {
313: this .passwordDataProvider = crsdp;
314: }
315:
316: private CachedRowSetDataProvider employeeDataProvider = new CachedRowSetDataProvider();
317:
318: public CachedRowSetDataProvider getEmployeeDataProvider() {
319: return employeeDataProvider;
320: }
321:
322: public void setEmployeeDataProvider(CachedRowSetDataProvider crsdp) {
323: this .employeeDataProvider = crsdp;
324: }
325:
326: // </editor-fold>
327:
328: /**
329: * <p>Construct a new Page bean instance.</p>
330: */
331: public Login() {
332: }
333:
334: /**
335: * <p>Callback method that is called whenever a page is navigated to,
336: * either directly via a URL, or indirectly via page navigation.
337: * Customize this method to acquire resources that will be needed
338: * for event handlers and lifecycle methods, whether or not this
339: * page is performing post back processing.</p>
340: *
341: * <p>Note that, if the current request is a postback, the property
342: * values of the components do <strong>not</strong> represent any
343: * values submitted with this request. Instead, they represent the
344: * property values that were saved for this view when it was rendered.</p>
345: */
346: @Override
347: public void init() {
348: // Perform initializations inherited from our superclass
349: super .init();
350: // Perform application initialization that must complete
351: // *before* managed components are initialized
352: // TODO - add your own initialiation code here
353:
354: // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
355: // Initialize automatically managed components
356: // *Note* - this logic should NOT be modified
357: try {
358: _init();
359: } catch (Exception e) {
360: log("Login Initialization Failure", e);
361: throw e instanceof FacesException ? (FacesException) e
362: : new FacesException(e);
363: }
364:
365: // </editor-fold>
366: // Perform application initialization that must complete
367: // *after* managed components are initialized
368: // TODO - add your own initialization code here
369: }
370:
371: /**
372: * <p>Callback method that is called after the component tree has been
373: * restored, but before any event processing takes place. This method
374: * will <strong>only</strong> be called on a postback request that
375: * is processing a form submit. Customize this method to allocate
376: * resources that will be required in your event handlers.</p>
377: */
378: @Override
379: public void preprocess() {
380: }
381:
382: /**
383: * <p>Callback method that is called just before rendering takes place.
384: * This method will <strong>only</strong> be called for the page that
385: * will actually be rendered (and not, for example, on a page that
386: * handled a postback and then navigated to a different page). Customize
387: * this method to allocate resources that will be required for rendering
388: * this page.</p>
389: */
390: @Override
391: public void prerender() {
392: }
393:
394: /**
395: * <p>Callback method that is called after rendering is completed for
396: * this request, if <code>init()</code> was called (regardless of whether
397: * or not this was the page that was actually rendered). Customize this
398: * method to release resources acquired in the <code>init()</code>,
399: * <code>preprocess()</code>, or <code>prerender()</code> methods (or
400: * acquired during execution of an event handler).</p>
401: */
402: @Override
403: public void destroy() {
404: passwordDataProvider.close();
405: employeeDataProvider.close();
406: }
407:
408: /**
409: * <p>Return a reference to the scoped data bean.</p>
410: */
411: protected ApplicationBean1 getApplicationBean1() {
412: return (ApplicationBean1) getBean("ApplicationBean1");
413: }
414:
415: /**
416: * <p>Return a reference to the scoped data bean.</p>
417: */
418: protected SessionBean1 getSessionBean1() {
419: return (SessionBean1) getBean("SessionBean1");
420: }
421:
422: /**
423: * <p>Return a reference to the scoped data bean.</p>
424: */
425: protected RequestBean1 getRequestBean1() {
426: return (RequestBean1) getBean("RequestBean1");
427: }
428:
429: public String login_action() {
430: // TODO: Process the action. Return value is a navigation
431: // case name where null will return to the same page.
432: Integer theUserId = (Integer) this .userId.getValue();
433: String thePassword = (String) this .password.getText();
434: // refresh to pick up newly added users
435: getPasswordDataProvider().refresh();
436: RowKey rowKey = getPasswordDataProvider().findFirst(
437: new String[] { "password.id", "password.password" },
438: new Object[] { theUserId, thePassword });
439: if (rowKey == null) {
440: error("Could not login user id '" + theUserId + "'");
441: return null;
442: }
443: getPasswordDataProvider().setCursorRow(rowKey);
444:
445: // refresh to pick up newly added users
446: getEmployeeDataProvider().refresh();
447: rowKey = getEmployeeDataProvider().findFirst(
448: new String[] { "employee.id" },
449: new Object[] { theUserId });
450: if (rowKey == null) {
451: error("Could not login user id '" + theUserId
452: + "'. Could not get the employee info.");
453: return null;
454: }
455:
456: getEmployeeDataProvider().setCursorRow(rowKey);
457:
458: getSessionBean1().setLoggedIn(true);
459: getSessionBean1().setLoggedInUserId(theUserId);
460: getSessionBean1().setLoggedInUserName(
461: getEmployeeDataProvider()
462: .getValue("employee.firstname")
463: + " "
464: + getEmployeeDataProvider().getValue(
465: "employee.lastname"));
466: return "vehicles";
467: }
468:
469: public String register_action() {
470: // TODO: Process the action. Return value is a navigation
471: // case name where null will return to the same page.
472: return "newuser";
473: }
474: }
|