home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / forms_flow_example.js < prev    next >
Encoding:
Text File  |  2004-07-12  |  2.6 KB  |  81 lines

  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. *     http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/Form.js");
  17.  
  18. function form1(form) {
  19.     var locale = determineLocale();
  20.     var model = form.getModel();
  21.     model.email = "bar@www.foo.com";
  22.     model.somebool = true;
  23.     model.account = 2;
  24.     model.cowheight = 4;
  25.     model.number1 = 1;
  26.     model.number2 = 3;
  27.     model.birthdate = new java.util.Date();
  28.     
  29.     model.contacts[0].firstname = "Jules";
  30.     model.contacts[1].firstname =  "Lucien";
  31.     model.contacts[2].firstname = "Chris";
  32.     model.drinks = ["Jupiler", "Coca Cola"];
  33.  
  34.     form.locale = locale;
  35.     form.showForm("form1-display-pipeline");
  36.     print("submitId = " + form.submitId);
  37.     if (form.isValid) {
  38.       print("visa=" + model.visa);  
  39.     } else {
  40.       print("Form is not valid");
  41.     }
  42.     // also store the form as a request attribute as the XSP isn't flow-aware
  43.     cocoon.request.setAttribute("form1", form.getWidget());
  44.     cocoon.sendPage("form1-success-pipeline.xsp");
  45. }
  46.  
  47. function selectCar() {
  48.     var form = new Form("forms/carselector_form.xml");
  49.     form.lookupWidget("make").setValue(cocoon.parameters.defaultMake);
  50.     form.showForm("carselector-display-pipeline");
  51.     cocoon.request.setAttribute("carselectorform", form.getWidget());
  52.     cocoon.sendPage("carselector-success-pipeline.xsp");
  53. }
  54.  
  55. var states = [
  56.     { key: "AL", value: "Alabama" },
  57.     { key: "AK", value: "Alaska" },
  58.     { key: "WY", value: "Wyoming" }
  59. ];
  60.  
  61. var countries = [
  62.     { key: "ad", value: "Andorra, Principality of" },
  63.     { key: "zw", value: "Zimbabwe" }
  64. ];
  65.  
  66. function selectCountry() {
  67.     var form = new Form("forms/countryselector_form.xml");
  68.     form.showForm("countryselector-display-pipeline");
  69.     cocoon.request.setAttribute("countryselectorform", form.getWidget());
  70.     cocoon.sendPage("countryselector-success-pipeline.xsp");
  71. }
  72.  
  73. function determineLocale() {
  74.     var localeParam = cocoon.request.get("locale");
  75.     if (localeParam != null && localeParam.length > 0) {
  76.         return Packages.org.apache.cocoon.i18n.I18nUtils.parseLocale(localeParam);
  77.     }
  78.     return null;
  79. }
  80.  
  81.