package es.ejie.frmk.presentacion.iu.taglib.html.table;

import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.TagSupport;

import org.displaytag.exception.TagStructureException;

/**
 * @author epesh
 * @version 1.0
 */
public class Q70SetPropertyTag extends BodyTagSupport implements Cloneable
{

    /**
     * property name
     */
    private String name;

    /**
     * property value
     */
    private String value;

    /**
     * Sets the name of the property
     * @param propertyName String
     */
    public void setName(String propertyName)
    {
        name = propertyName;
    }

    /**
     * Sets the value of the property
     * @param propertyValue String
     */
    public void setValue(String propertyValue)
    {
        value = propertyValue;
    }

    /**
     * Passes attribute information up to the parent Q70TableTag.
     * <p>
     * When we hit the end of the tag, we simply let our parent (which better be a Q70TableTag) know what the user wants
     * to change a property value, and we pass the name/value pair that the user gave us, up to the parent
     * </p>
     * @return <code>TagSupport.EVAL_PAGE</code>
     * @throws TagStructureException if no parent table tag is found
     * @see javax.servlet.jsp.tagext.Tag#doEndTag()
     */
    public int doEndTag() throws TagStructureException
    {

        Q70TableTag tableTag = (Q70TableTag) findAncestorWithClass(this, Q70TableTag.class);

        if (tableTag == null)
        {
            throw new TagStructureException(getClass(), "property", "table");
        }

        tableTag.setProperty(name, value);

        return TagSupport.EVAL_PAGE;
    }

}
