FileDocCategorySizeDatePackage
ContainerTag.javaAPI DocExample1564Sat Nov 22 20:33:22 GMT 2003cvexample.view

ContainerTag.java

package cvexample.view;

import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
import javax.servlet.*;
import java.io.*;

import cvexample.controller.*;

/**
 * A custom tag for including containers within a JSP by name.  This tag also
 * contains nested ContainerIncludeTags, which use it to find their assoicated
 * includes.
 */
public class ContainerTag extends TagSupport {
    /** the name of the view in the request */
    private static final String VIEW_ATTR = "view";
    
    /** the name of the container */
    private String name;   
    
    /** the view assoicated with this container */
    private View view;
      
    /**
     * Determine if the named view exists.  If it does, proceed with
     * any nested tage.  If it doesn't, just abort.
     */
    public int doStartTag() throws JspException, JspException { 
        // find the view in the request
        view = (View) pageContext.getRequest().getAttribute(VIEW_ATTR);
        
        // see if it has the desired container
        if (!view.hasContainer(name))
            return SKIP_BODY;
        
        return EVAL_BODY_INCLUDE;
    }

    /**
     * Get the view associated with this container.  Used by
     * ContainerIncludeTag
     */
    public View getView() {
        return view;
    }
       
    /**
     * Called by the tag itself to set the name of the container
     */
    public void setName(String value) {
        name = value;
    }
    
    /**
     * Get the name of the container
     */
    public String getName() {
        return name;
    }
}