01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.forms.formmodel;
18:
19: import org.apache.cocoon.forms.util.DomHelper;
20: import org.w3c.dom.Element;
21:
22: /**
23: * Builds a <code><fd:submit></code> widget. A submit is an action that
24: * terminates the current form. It can either require the form to be valid
25: * (in which case it will be redisplayed if not valid) or terminate it without
26: * validation (e.g. a "cancel" button).
27: *
28: * <p>The syntax is as follows:
29: * <pre>
30: * <wd:submit id="sub-id" command="cmd" validate="false"/>
31: * </pre>
32: *
33: * The "validate" attribute can have the value <code>true</code> or
34: * <code>false</code> and determines if the form is to be validated
35: * (defaults to true).</p>
36: *
37: * @version $Id: SubmitDefinitionBuilder.java 517843 2007-03-13 20:09:32Z vgritsenko $
38: */
39: public final class SubmitDefinitionBuilder extends
40: ActionDefinitionBuilder {
41:
42: public WidgetDefinition buildWidgetDefinition(Element widgetElement)
43: throws Exception {
44: SubmitDefinition definition = new SubmitDefinition();
45: super .setupDefinition(widgetElement, definition);
46:
47: // parse "@validate"
48: if (widgetElement.hasAttribute("validate")) {
49: definition.setValidateForm(DomHelper.getAttributeAsBoolean(
50: widgetElement, "validate", true));
51: }
52:
53: definition.makeImmutable();
54:
55: return definition;
56: }
57: }
|