/*
 * $Id: DynaCheckboxTag.java,v 1.5 2003/12/24 10:12:04 bigmac Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: DynaCheckboxTag.java,v $
 * Revision 1.5  2003/12/24 10:12:04  bigmac
 * Projektweite Import-Optimierung
 *
 * Revision 1.4  2003/07/31 13:59:27  bigmac
 * Compilerwarnungen beseitigt
 *
 * Revision 1.3  2003/07/23 10:45:33  marbobo
 * -unnötige Importanweisungen entfernt
 *
 * Revision 1.2  2002/12/14 04:34:51  koppy
 * <No Comment Entered>
 *
 * Revision 1.1  2002/12/12 02:35:38  koppy
 * Acl editing feature for categories added
 *
 */

package vkc.view.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.struts.taglib.html.CheckboxTag;


/**
 * Checkbox Tag für die Verwendung in map-backed ActionForms
 *
 * @author koppy
 */
public class DynaCheckboxTag extends CheckboxTag {

    private static String defaultDynaProp = "dynaValue";
    /**
     * Name der Methode für das Setzen dynamischer Daten
     * in der map-backed ActionForm
     */
    private String dynaProperty = defaultDynaProp;
    private String dynaValue = null;
    private String dynaId = null;


    /**
     * Konstruktor
     */
    public DynaCheckboxTag() {
        super();
	this.setValue( "true" );
    }


    public void setDynaValue(String dynaValue) {
        this.dynaValue = dynaValue;
    }

    public String getDynaValue() {
        return dynaValue;
    }

    public void setDynaProperty(String dynaProperty) {
        this.dynaProperty = dynaProperty;
    }
    public String getDynaProperty() {
        return dynaProperty;
    }
    public String getDynaId() {
        return dynaId;
    }
    public void setDynaId(String dynaId) {
        this.dynaId = dynaId;
    }

    /**
     * Sets the property to dynaProperty(dynaValue + bean(dynaId))
     * @return
     * @throws JspException
     * @see OptionTag
     */
    public int doStartTag() throws JspException {

	String additionalId = "";
	if( getDynaId() != null ) {
	    Object o = pageContext.getAttribute( this.getDynaId(), PageContext.PAGE_SCOPE );
	    if( o != null ) {
		additionalId = o.toString();
	    }
	}

	this.setProperty( this.getDynaProperty() + PropertyUtils.MAPPED_DELIM
			  + this.getDynaValue()
			  + additionalId
			  + PropertyUtils.MAPPED_DELIM2 );

	return super.doStartTag();
    }

    /**
     * Allokierte Resourcen wieder freigeben
     */
    public void release() {
        super.release();
        this.dynaProperty = defaultDynaProp;
	this.dynaValue = null;
	this.dynaId = null;
    }
}