001 // Copyright 2007 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.contrib.ajax; 016 017 import java.util.HashMap; 018 import java.util.Map; 019 import org.apache.tapestry.IMarkupWriter; 020 import org.apache.tapestry.IRequestCycle; 021 import org.apache.tapestry.IScript; 022 import org.apache.tapestry.PageRenderSupport; 023 import org.apache.tapestry.TapestryUtils; 024 import org.apache.tapestry.components.Any; 025 026 /** 027 * @since 4.1.2 028 */ 029 public abstract class AjaxStatus extends Any 030 { 031 public abstract IScript getScript(); 032 033 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) 034 { 035 // render as if an Any component 036 super.renderComponent(writer, cycle); 037 // then add the script 038 if(!cycle.isRewinding()) { 039 PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, this); 040 Map symbols = new HashMap(); 041 symbols.put("id", getClientId()); 042 getScript().execute(this, cycle, pageRenderSupport, symbols); 043 } 044 } 045 }