001// Copyright 2008 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 015package org.apache.tapestry5.internal.renderers; 016 017import org.apache.tapestry5.EventContext; 018import org.apache.tapestry5.MarkupWriter; 019import org.apache.tapestry5.ioc.annotations.Primary; 020import org.apache.tapestry5.services.ObjectRenderer; 021 022/** 023 * Renders out the values stored inside a {@link EventContext}. 024 */ 025public class EventContextRenderer implements ObjectRenderer<EventContext> 026{ 027 private final ObjectRenderer masterRenderer; 028 029 public EventContextRenderer(@Primary ObjectRenderer masterRenderer) 030 { 031 this.masterRenderer = masterRenderer; 032 } 033 034 035 public void render(EventContext object, MarkupWriter writer) 036 { 037 int count = object.getCount(); 038 039 if (count == 0) return; 040 041 writer.element("ul", "class", "t-data-list"); 042 043 for (int i = 0; i < count; i++) 044 { 045 writer.element("li"); 046 047 masterRenderer.render(object.get(Object.class, i), writer); 048 049 writer.end(); 050 } 051 052 writer.end(); 053 } 054}