001// Copyright 2004, 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.form; 016 017import org.apache.tapestry.IMarkupWriter; 018import org.apache.tapestry.IRequestCycle; 019 020/** 021 * Implements a component that manages an HTML <input type=button> form element. [ <a 022 * href="../../../../../ComponentReference/Button.html">Component Reference </a>] 023 * <p> 024 * This component is useful for attaching JavaScript onclick event handlers. 025 * 026 * @author Howard Lewis Ship 027 * @author Paul Geerts 028 * @author Malcolm Edgar 029 * @author Paul Ferraro 030 */ 031public abstract class Button extends AbstractFormComponent 032{ 033 /** 034 * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter, 035 * org.apache.tapestry.IRequestCycle) 036 */ 037 protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle) 038 { 039 writer.begin("button"); 040 writer.attribute("type", "button"); 041 writer.attribute("name", getName()); 042 043 if (isDisabled()) 044 { 045 writer.attribute("disabled", "disabled"); 046 } 047 048 renderIdAttribute(writer, cycle); 049 050 renderInformalParameters(writer, cycle); 051 052 String label = getLabel(); 053 054 if (label != null) 055 writer.print(label); 056 else 057 renderBody(writer, cycle); 058 059 writer.end(); 060 } 061 062 /** 063 * @see org.apache.tapestry.form.AbstractFormComponent#rewindFormComponent(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle) 064 */ 065 protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle) 066 { 067 // Do nothing 068 } 069 070 /** 071 * @see org.apache.tapestry.form.IFormComponent#getClientId() 072 */ 073 public String getClientId() 074 { 075 return null; 076 } 077 078 /** 079 * @see org.apache.tapestry.form.IFormComponent#getDisplayName() 080 */ 081 public String getDisplayName() 082 { 083 return null; 084 } 085 086 /** 087 * @see org.apache.tapestry.form.IFormComponent#isDisabled() 088 */ 089 public boolean isDisabled() 090 { 091 return false; 092 } 093 094 public abstract String getLabel(); 095}