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.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.Calendar;
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.TextField;
059: import javax.faces.FacesException;
060: import javax.faces.application.FacesMessage;
061: import javax.faces.component.UIComponent;
062: import javax.faces.component.UIInput;
063: import javax.faces.component.html.HtmlPanelGrid;
064: import javax.faces.context.FacesContext;
065: import javax.faces.event.ValueChangeEvent;
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 UpdatePage 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: tripDataProvider
086: .setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.tripRowSet}"));
087: }
088:
089: private Page page1 = new Page();
090:
091: public Page getPage1() {
092: return page1;
093: }
094:
095: public void setPage1(Page p) {
096: this .page1 = p;
097: }
098:
099: private Html html1 = new Html();
100:
101: public Html getHtml1() {
102: return html1;
103: }
104:
105: public void setHtml1(Html h) {
106: this .html1 = h;
107: }
108:
109: private Head head1 = new Head();
110:
111: public Head getHead1() {
112: return head1;
113: }
114:
115: public void setHead1(Head h) {
116: this .head1 = h;
117: }
118:
119: private Link link1 = new Link();
120:
121: public Link getLink1() {
122: return link1;
123: }
124:
125: public void setLink1(Link l) {
126: this .link1 = l;
127: }
128:
129: private Body body1 = new Body();
130:
131: public Body getBody1() {
132: return body1;
133: }
134:
135: public void setBody1(Body b) {
136: this .body1 = b;
137: }
138:
139: private Form form1 = new Form();
140:
141: public Form getForm1() {
142: return form1;
143: }
144:
145: public void setForm1(Form f) {
146: this .form1 = f;
147: }
148:
149: private HtmlPanelGrid mainPanel = new HtmlPanelGrid();
150:
151: public HtmlPanelGrid getMainPanel() {
152: return mainPanel;
153: }
154:
155: public void setMainPanel(HtmlPanelGrid hpg) {
156: this .mainPanel = hpg;
157: }
158:
159: private HtmlPanelGrid tripPanel = new HtmlPanelGrid();
160:
161: public HtmlPanelGrid getTripPanel() {
162: return tripPanel;
163: }
164:
165: public void setTripPanel(HtmlPanelGrid hpg) {
166: this .tripPanel = hpg;
167: }
168:
169: private Label label1 = new Label();
170:
171: public Label getLabel1() {
172: return label1;
173: }
174:
175: public void setLabel1(Label l) {
176: this .label1 = l;
177: }
178:
179: private Calendar dateCalendar = new Calendar();
180:
181: public Calendar getDateCalendar() {
182: return dateCalendar;
183: }
184:
185: public void setDateCalendar(Calendar c) {
186: this .dateCalendar = c;
187: }
188:
189: private Label label2 = new Label();
190:
191: public Label getLabel2() {
192: return label2;
193: }
194:
195: public void setLabel2(Label l) {
196: this .label2 = l;
197: }
198:
199: private TextField fromCity = new TextField();
200:
201: public TextField getFromCity() {
202: return fromCity;
203: }
204:
205: public void setFromCity(TextField tf) {
206: this .fromCity = tf;
207: }
208:
209: private Label label3 = new Label();
210:
211: public Label getLabel3() {
212: return label3;
213: }
214:
215: public void setLabel3(Label l) {
216: this .label3 = l;
217: }
218:
219: private TextField toCity = new TextField();
220:
221: public TextField getToCity() {
222: return toCity;
223: }
224:
225: public void setToCity(TextField tf) {
226: this .toCity = tf;
227: }
228:
229: private Label label4 = new Label();
230:
231: public Label getLabel4() {
232: return label4;
233: }
234:
235: public void setLabel4(Label l) {
236: this .label4 = l;
237: }
238:
239: private DropDown tripType = new DropDown();
240:
241: public DropDown getTripType() {
242: return tripType;
243: }
244:
245: public void setTripType(DropDown dd) {
246: this .tripType = dd;
247: }
248:
249: private HtmlPanelGrid buttonPanel = new HtmlPanelGrid();
250:
251: public HtmlPanelGrid getButtonPanel() {
252: return buttonPanel;
253: }
254:
255: public void setButtonPanel(HtmlPanelGrid hpg) {
256: this .buttonPanel = hpg;
257: }
258:
259: private Button updateButton = new Button();
260:
261: public Button getUpdateButton() {
262: return updateButton;
263: }
264:
265: public void setUpdateButton(Button b) {
266: this .updateButton = b;
267: }
268:
269: private Button cancel = new Button();
270:
271: public Button getCancel() {
272: return cancel;
273: }
274:
275: public void setCancel(Button b) {
276: this .cancel = b;
277: }
278:
279: private MessageGroup messageGroup = new MessageGroup();
280:
281: public MessageGroup getMessageGroup() {
282: return messageGroup;
283: }
284:
285: public void setMessageGroup(MessageGroup mg) {
286: this .messageGroup = mg;
287: }
288:
289: private CachedRowSetDataProvider tripDataProvider = new CachedRowSetDataProvider();
290:
291: public CachedRowSetDataProvider getTripDataProvider() {
292: return tripDataProvider;
293: }
294:
295: public void setTripDataProvider(CachedRowSetDataProvider crsdp) {
296: this .tripDataProvider = crsdp;
297: }
298:
299: // </editor-fold>
300:
301: /**
302: * <p>Construct a new Page bean instance.</p>
303: */
304: public UpdatePage() {
305: }
306:
307: /**
308: * <p>Callback method that is called whenever a page is navigated to,
309: * either directly via a URL, or indirectly via page navigation.
310: * Customize this method to acquire resources that will be needed
311: * for event handlers and lifecycle methods, whether or not this
312: * page is performing post back processing.</p>
313: *
314: * <p>Note that, if the current request is a postback, the property
315: * values of the components do <strong>not</strong> represent any
316: * values submitted with this request. Instead, they represent the
317: * property values that were saved for this view when it was rendered.</p>
318: */
319: @Override
320: public void init() {
321: // Perform initializations inherited from our superclass
322: super .init();
323: // Perform application initialization that must complete
324: // *before* managed components are initialized
325: // TODO - add your own initialiation code here
326:
327: // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
328: // Initialize automatically managed components
329: // *Note* - this logic should NOT be modified
330: try {
331: _init();
332: } catch (Exception e) {
333: log("UpdatePage Initialization Failure", e);
334: throw e instanceof FacesException ? (FacesException) e
335: : new FacesException(e);
336: }
337:
338: // </editor-fold>
339: // Perform application initialization that must complete
340: // *after* managed components are initialized
341: // TODO - add your own initialization code here
342: Integer tid = (Integer) getSessionBean1().getCurrentTripId();
343: RowKey tripRowKey = tripDataProvider.findFirst("TRIP.TRIPID",
344: tid);
345: tripDataProvider.setCursorRow(tripRowKey);
346: }
347:
348: /**
349: * <p>Callback method that is called after the component tree has been
350: * restored, but before any event processing takes place. This method
351: * will <strong>only</strong> be called on a postback request that
352: * is processing a form submit. Customize this method to allocate
353: * resources that will be required in your event handlers.</p>
354: */
355: @Override
356: public void preprocess() {
357: }
358:
359: /**
360: * <p>Callback method that is called just before rendering takes place.
361: * This method will <strong>only</strong> be called for the page that
362: * will actually be rendered (and not, for example, on a page that
363: * handled a postback and then navigated to a different page). Customize
364: * this method to allocate resources that will be required for rendering
365: * this page.</p>
366: */
367: @Override
368: public void prerender() {
369: // bind trip detail fields
370: java.sql.Date date = (java.sql.Date) tripDataProvider
371: .getValue("TRIP.DEPDATE");
372: dateCalendar.setValue(date);
373: }
374:
375: /**
376: * <p>Callback method that is called after rendering is completed for
377: * this request, if <code>init()</code> was called (regardless of whether
378: * or not this was the page that was actually rendered). Customize this
379: * method to release resources acquired in the <code>init()</code>,
380: * <code>preprocess()</code>, or <code>prerender()</code> methods (or
381: * acquired during execution of an event handler).</p>
382: */
383: @Override
384: public void destroy() {
385: tripDataProvider.close();
386: }
387:
388: /**
389: * <p>Return a reference to the scoped data bean.</p>
390: */
391: protected RequestBean1 getRequestBean1() {
392: return (RequestBean1) getBean("RequestBean1");
393: }
394:
395: /**
396: * <p>Return a reference to the scoped data bean.</p>
397: */
398: protected SessionBean1 getSessionBean1() {
399: return (SessionBean1) getBean("SessionBean1");
400: }
401:
402: /**
403: * <p>Return a reference to the scoped data bean.</p>
404: */
405: protected ApplicationBean1 getApplicationBean1() {
406: return (ApplicationBean1) getBean("ApplicationBean1");
407: }
408:
409: public String updateButton_action() {
410: // TODO: Process the action. Return value is a navigation
411: // case name where null will return to the same page.
412: try {
413: java.util.Date uDate = (java.util.Date) dateCalendar
414: .getValue();
415: if (uDate != null) {
416: java.sql.Date date = new java.sql.Date(uDate.getTime());
417: tripDataProvider.setValue("TRIP.DEPDATE", date);
418: }
419: tripDataProvider.commitChanges();
420: } catch (Exception e) {
421: error("Cannot commit changes -- " + e);
422: log("Exception: " + e);
423: }
424: return "updated";
425: }
426:
427: public String cancel_action() {
428: // TODO: Process the action. Return value is a navigation
429: // case name where null will return to the same page.
430: return "noUpdate";
431: }
432:
433: public void tripType_processValueChange(ValueChangeEvent event) {
434: // TODO: Replace with your code
435: tripDataProvider.setValue("TRIP.TRIPTYPEID", tripType
436: .getValue());
437: }
438:
439: // Fix for 118985
440: private void multipleValidate(UIComponent component, Object value) {
441: String theCity = (String) value;
442: if (theCity.length() > 32) {
443: ((UIInput) component).setValid(false);
444: throw new ValidatorException(new FacesMessage(
445: "Error: City name must be less than 32 characters"));
446: }
447: for (int i = 0; i < theCity.length(); i++) {
448: if (Character.isDigit(theCity.charAt(i))) {
449: ((UIInput) component).setValid(false);
450: throw new ValidatorException(new FacesMessage(
451: "Error: City name must contain no digits"));
452: }
453: }
454: }
455:
456: public void fromCity_validate(FacesContext context,
457: UIComponent component, Object value) {
458: multipleValidate(component, value);
459: }
460:
461: public void toCity_validate(FacesContext context,
462: UIComponent component, Object value) {
463: multipleValidate(component, value);
464: }
465:
466: }
|