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.MarkupWriter;
018import org.apache.tapestry5.ioc.annotations.Primary;
019import org.apache.tapestry5.services.ObjectRenderer;
020
021import java.util.List;
022
023/**
024 * Renders a List, but rendering an unordered list.
025 */
026public class ListRenderer implements ObjectRenderer<List>
027{
028    private final ObjectRenderer masterRenderer;
029
030    public ListRenderer(@Primary ObjectRenderer masterRenderer)
031    {
032        this.masterRenderer = masterRenderer;
033    }
034
035    public void render(List list, MarkupWriter writer)
036    {
037        if (list.isEmpty())
038        {
039            writer.element("em");
040            writer.write("empty list");
041            writer.end();
042            return;
043        }
044
045        writer.element("ul", "class", "t-data-list");
046
047        for (Object element : list)
048        {
049            writer.element("li");
050
051            masterRenderer.render(element, writer);
052
053            writer.end();
054        }
055
056        writer.end();
057    }
058}