    001// Copyright 2008, 2010, 2011 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.corelib.components;
    016
    017import org.apache.tapestry5.ComponentResources;
    018import org.apache.tapestry5.MarkupWriter;
    019import org.apache.tapestry5.annotations.Environmental;
    020import org.apache.tapestry5.annotations.SupportsInformalParameters;
    021import org.apache.tapestry5.corelib.internal.AjaxFormLoopContext;
    022import org.apache.tapestry5.ioc.annotations.Inject;
    023
    024/**
    025 * Used inside a {@link org.apache.tapestry5.corelib.components.AjaxFormLoop} to remove the current row from the loop.
    026 * This fires a server-side event (from the AjaxFormLoop component); the event context is the object to be removed. On
    027 * the client-side, the element for the row is hidden, then removed altogether.
    028 *
    029 * @tapestrydoc
    030 */
    031@SupportsInformalParameters
    032public class RemoveRowLink
    033{
    034    @Inject
    035    private ComponentResources resources;
    036
    037    @Environmental
    038    private AjaxFormLoopContext context;
    039
    040    void beginRender(MarkupWriter writer)
    041    {
    042        writer.element("a",
    043
    044                "href", "#",
    045
    046                "data-afl-behavior", "remove",
    047
    048                "data-afl-row-value", context.encodedRowValue());
    049
    050        resources.renderInformalParameters(writer);
    051    }
    052
    053    void afterRender(MarkupWriter writer)
    054    {
    055        writer.end();
    056    }
    057}