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