001 // Copyright May 4, 2006 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 package org.apache.tapestry.dojo.form; 015 016 import org.apache.tapestry.IMarkupWriter; 017 import org.apache.tapestry.IRequestCycle; 018 import org.apache.tapestry.form.AbstractFormComponent; 019 020 021 /** 022 * Represents a dojo widget that manages an html form input 023 * field. 024 * 025 * @author jkuhnert 026 * @since 4.1 027 */ 028 public abstract class AbstractFormWidget extends AbstractFormComponent implements IFormWidget 029 { 030 031 public abstract void setDestroy(boolean destroy); 032 033 /** 034 * Determined dynamically at runtime during rendering, informs widget implementations 035 * if they should destroy their client side widget equivalents or leave them in tact. 036 * 037 * @return True if the widget should be destroyed on this render, false otherwise. 038 */ 039 public abstract boolean getDestroy(); 040 041 /** 042 * {@inheritDoc} 043 */ 044 public void renderWidget(IMarkupWriter writer, IRequestCycle cycle) 045 { 046 renderComponent(writer, cycle); 047 } 048 049 /** 050 * {@inheritDoc} 051 */ 052 protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle) 053 { 054 if(!cycle.isRewinding()) { 055 056 if (!cycle.getResponseBuilder().isDynamic() 057 || cycle.getResponseBuilder().explicitlyContains(this)) { 058 059 setDestroy(false); 060 } else { 061 062 setDestroy(true); 063 } 064 } 065 066 renderFormWidget(writer, cycle); 067 } 068 069 /** 070 * {@inheritDoc} 071 */ 072 protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle) 073 { 074 rewindFormWidget(writer, cycle); 075 } 076 077 /** 078 * Called when rendering a form widget. 079 * 080 * @param writer 081 * The markup writer to render with. 082 * @param cycle 083 * The cycle associated with request. 084 */ 085 protected abstract void renderFormWidget(IMarkupWriter writer, IRequestCycle cycle); 086 087 /** 088 * Called during form submission to retrieve submitted input values. 089 * Components should do any validation/retrieval of values in this method. 090 * 091 * @param writer 092 * The passed in {@link IMarkupWriter} will be a {@link org.apache.tapestry.engine.NullWriter}, making 093 * any content written ignored. 094 * @param cycle 095 * Typically used to retrieve submitted value via <code>cycle.getParameter(getName())</code>. 096 */ 097 protected abstract void rewindFormWidget(IMarkupWriter writer, IRequestCycle cycle); 098 }