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.tapestry.AbstractComponent; 018 import org.apache.tapestry.IMarkupWriter; 019 import org.apache.tapestry.IRequestCycle; 020 import org.apache.tapestry.form.IPropertySelectionModel; 021 022 /** 023 * A high level component used to render a drop-down list of options that the user may select. 024 * 025 * Informal parameters are applied to the <select> tag. To have greater control over the 026 * <option> tags, you must use a Select and Option or a concrete class 027 * of {@link org.apache.tapestry.link.ILinkRenderer} with the {@link OptionRenderer}. 028 * 029 * @author David Solis 030 */ 031 032 public abstract class PropertySelection extends AbstractComponent 033 { 034 /** 035 * @see AbstractComponent#renderComponent(IMarkupWriter, IRequestCycle) 036 **/ 037 038 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) 039 { 040 boolean render = !cycle.isRewinding(); 041 042 if (render) 043 { 044 IPropertySelectionModel model = getModel(); 045 046 writer.begin("select"); 047 048 writer.attribute("name", getName()); 049 050 renderInformalParameters(writer, cycle); 051 052 writer.println(); 053 054 int count = model.getOptionCount(); 055 056 for (int i = 0; i < count; i++) 057 { 058 059 writer.begin("option"); 060 writer.attribute("value", model.getValue(i)); 061 062 writer.print(model.getLabel(i)); 063 064 writer.end(); 065 writer.println(); 066 } 067 068 writer.end(); 069 } 070 } 071 072 public abstract IPropertySelectionModel getModel(); 073 074 public abstract String getName(); 075 }