Flowscript

Flowscript listing

Here's the complete Flowscript code which drives the bean editor application:

tour.js
0001 /*
0002 * Copyright 1999-2004 The Apache Software Foundation.
0003 *
0004 * Licensed under the Apache License, Version 2.0 (the "License");
0005 * you may not use this file except in compliance with the License.
0006 * You may obtain a copy of the License at
0007 *
0008 * http://www.apache.org/licenses/LICENSE-2.0
0009 *
0010 * Unless required by applicable law or agreed to in writing, software
0011 * distributed under the License is distributed on an "AS IS" BASIS,
0012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013 * See the License for the specific language governing permissions and
0014 * limitations under the License.
0015 */

0017 // flowscript for supersonic tour example app

0019 // Load the javascript Cocoon Forms library
0020 cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/Form.js");

0022 // Access java "database" facade object
0023 var db = Packages.org.apache.cocoon.samples.tour.beans.DatabaseFacade.getInstance();

0025 // Query all TaskBean objects and display them
0026 function query_allTasks() {
0027 var list = db.getTasks();

0029 cocoon.sendPage("internal/generate-view/taskList", {
0030 title : "List of tasks",
0031 task : list,
0032 db : db
0033 });
0034 }

0036 // Query a single TaskBean object and display it
0037 function query_singleTask() {
0038 var id = cocoon.request.getParameter("taskId");
0039 var bean = db.getTaskBeanById(id);
0040 displayTaskBean(id,bean);
0041 }

0043 // Edit a single TaskBean object using Cocoon Forms
0044 function singleTaskEditor(form) {
0045 var id = cocoon.request.getParameter("taskId");
0046 var bean = db.getTaskBeanById(id);

0048 form.load(bean);
0049 form.showForm("internal/show-form/singleTask");
0050 form.save(bean);
0051 displayTaskBean(id,bean);
0052 }

0054 // Display a single TaskBean
0055 function displayTaskBean(id,bean) {
0056 cocoon.sendPage("internal/generate-view/singleTask", {
0057 title : "Task #" + id,
0058 task : bean,
0059 selectedTaskId : id
0060 });
0061 }