01: /*
02: WikiForms - a WikiPage FORM handler for JSPWiki.
03:
04: Copyright (C) 2003 BaseN.
05:
06: JSPWiki Copyright (C) 2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
07:
08: This program is free software; you can redistribute it and/or modify
09: it under the terms of the GNU Lesser General Public License as published
10: by the Free Software Foundation; either version 2.1 of the License, or
11: (at your option) any later version.
12:
13: This program is distributed in the hope that it will be useful,
14: but WITHOUT ANY WARRANTY; without even the implied warranty of
15: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: GNU Lesser General Public License for more details.
17:
18: You should have received a copy of the GNU Lesser General Public License
19: along with this program; if not, write to the Free Software
20: */
21: package com.ecyrd.jspwiki.forms;
22:
23: import com.ecyrd.jspwiki.*;
24: import com.ecyrd.jspwiki.plugin.WikiPlugin;
25:
26: /**
27: */
28: public abstract class FormElement implements WikiPlugin {
29: /**
30: * In order to make the form-to-handler parameter transfer easier,
31: * we prefix all user-specified FORM element names with HANDLERPARAM_PREFIX
32: * the HTML output. This lets us differentiate user-defined FormHandler
33: * parameters from Form parameters.
34: * The submit handler must then use MapUtil.requestToMap() to
35: * strip them before executing the handler itself.
36: */
37: public static final String HANDLERPARAM_PREFIX = "nbf_";
38:
39: /**
40: * The submit servlet may decide to store a FormInfo with user-entered
41: * form values in the Session. It should use this name, and this class
42: * checks for it to pre-fill fields from a previous form submit.
43: */
44: public static final String FORM_VALUES_CARRIER = "nbpf_values";
45:
46: // Show values:
47: public static final String HIDE_SUCCESS = "onsuccess";
48:
49: // Parameter names:
50: /** Plugin parameter, optional, indicates servlet to post to. */
51: public static final String PARAM_SUBMITHANDLER = "submit";
52: /** Plugin parameter, mandatory, indicates what form element to insert. */
53: public static final String PARAM_ELEMENT = "element";
54: /**
55: * Plugin parameter, mandatory in output element, indicates
56: * WikiPlugin to use to handle form submitted data.
57: */
58: public static final String PARAM_HANDLER = "handler";
59: /** Plugin parameter, mandatory in open/output: name of the form. */
60: public static final String PARAM_FORM = "form";
61: /** Plugin parameter, mandatory in input elements: name of an element. */
62: public static final String PARAM_INPUTNAME = "name";
63: /** Plugin parameter, optional: default value for an input. */
64: public static final String PARAM_VALUE = "value";
65: /** Experimental: hide the form if it was submitted successfully. */
66: public static final String PARAM_HIDEFORM = "hide";
67:
68: /** If set to 'handler' in output element, the handler plugin is
69: * called even on first invocation (no submit). The plugin can
70: * then place values into its parameter map, and these are seen by
71: * subsequent Form elements. (Store a value in the plugin with the
72: * same key as an input element, and the value will be visible in
73: * the initial form.)
74: */
75: public static final String PARAM_POPULATE = "populate";
76: /** HTTP parameter, inserted as hidden variable into the generated form. */
77: public static final String PARAM_FORMNAMEHIDDEN = "formname";
78:
79: // Key to store the form info container in the context by:
80: //public static final String CONTEXT_FORMINFO = "FormPluginInfo";
81:
82: /**
83: * Utility method stores a FormInfo object into the WikiContext.
84: */
85: protected void storeFormInfo(WikiContext ctx, FormInfo info) {
86: ctx.setVariable(FORM_VALUES_CARRIER, info);
87: }
88:
89: /**
90: * Attempts to retrieve information on the currently handled
91: * form from the WikiContext.
92: */
93: protected FormInfo getFormInfo(WikiContext ctx) {
94: return (FormInfo) ctx.getVariable(FORM_VALUES_CARRIER);
95: }
96: }
|