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 015 package org.apache.tapestry.wml; 016 017 import org.apache.hivemind.HiveMind; 018 import org.apache.tapestry.AbstractComponent; 019 import org.apache.tapestry.IMarkupWriter; 020 import org.apache.tapestry.IRequestCycle; 021 022 /** 023 * This component serves as a container for one item that is listed as a choice in a {@link Select}. 024 * A {@link Select}offers a selection of choices from which usersu may choose one or more items. 025 * The select list is created using a select element which contains a collection of option elements. 026 * A string or text describing the item appears between the opening and closing option tags. In 027 * order to have a dynamic onpick attribute it is better to use a concrete class of 028 * {@link org.apache.tapestry.link.ILinkRenderer}with the {@link OptionRenderer}. 029 * 030 * @author David Solis 031 * @since 3.0 032 */ 033 034 public abstract class Option extends AbstractComponent 035 { 036 037 /** 038 * @see org.apache.tapestry.AbstractComponent#renderComponent(IMarkupWriter, IRequestCycle) 039 */ 040 041 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) 042 { 043 boolean render = !cycle.isRewinding(); 044 045 if (render) 046 { 047 writer.begin("option"); 048 049 String value = getValue(); 050 if (HiveMind.isNonBlank(value)) 051 writer.attribute("value", value); 052 053 renderInformalParameters(writer, cycle); 054 055 renderBody(writer, cycle); 056 057 writer.end(); 058 } 059 } 060 061 public abstract String getValue(); 062 }