001// Copyright 2005 The Apache Software Foundation
002//
003// Licensed under the Apache License, Version 2.0 (the "License");
004// you may not use this file except in compliance with the License.
005// You may obtain a copy of the License at
006//
007//     http://www.apache.org/licenses/LICENSE-2.0
008//
009// Unless required by applicable law or agreed to in writing, software
010// distributed under the License is distributed on an "AS IS" BASIS,
011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012// See the License for the specific language governing permissions and
013// limitations under the License.
014
015package org.apache.tapestry.wml;
016
017import org.apache.hivemind.HiveMind;
018import org.apache.tapestry.IForm;
019import org.apache.tapestry.IMarkupWriter;
020import org.apache.tapestry.IRequestCycle;
021import org.apache.tapestry.form.FormEventType;
022import org.apache.tapestry.form.FormSupportImpl;
023
024/**
025 * Subclass of {@link org.apache.tapestry.form.FormSupportImpl} that adjusts the output markup
026 * to conform to WML.
027 * 
028 * @author Howard M. Lewis Ship
029 * @since 4.0
030 */
031public class GoFormSupportImpl extends FormSupportImpl
032{
033    public GoFormSupportImpl(IMarkupWriter writer, IRequestCycle cycle, IForm form)
034    {
035        super(writer, cycle, form);
036    }
037
038    protected void writeTag(IMarkupWriter writer, String method, String url)
039    {
040        writer.begin("go");
041        writer.attribute("method", method);
042        writer.attribute("href", url);
043    }
044
045    protected void writeHiddenFields()
046    {
047        // The super-implementation writes a <div> tag that's not
048        // valid as WML.
049
050        writeHiddenFieldList();
051    }
052
053    protected void writeHiddenField(IMarkupWriter writer, String name, String id, String value)
054    {
055        writer.beginEmpty("postfield");
056        writer.attribute("name", name);
057
058        if (HiveMind.isNonBlank(id))
059            writer.attribute("id", id);
060
061        writer.attribute("value", value);
062        writer.println();
063    }
064
065    public void addEventHandler(FormEventType type, String functionName)
066    {
067        throw new UnsupportedOperationException(
068                "addEventHandler() not supported for WML Go component.");
069    }
070
071    protected void emitEventManagerInitialization()
072    {
073    }
074}