You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by bu...@apache.org on 2004/10/19 15:08:01 UTC
DO NOT REPLY [Bug 31774] -
[TILES] PresentTag
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=31774>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=31774
[TILES] PresentTag
------- Additional Comments From JordiMcLeod@gmail.com 2004-10-19 13:08 -------
package org.apache.struts.taglib.tiles;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.struts.taglib.tiles.ComponentConstants;
import org.apache.struts.tiles.ComponentContext;
/**
* Render the body only if the specified component/template attribute property
* id present.
*/
public class PresentTag extends TagSupport implements ComponentConstants
{
private String attribute = null;
/** Role attribute */
private String role = null;
/**
* Default constructor.
*/
public PresentTag()
{
super();
}
/**
* Release all allocated resources.
*/
public void release()
{
super.release();
attribute = null;
role = null;
}
/**
* Set attribute.
*
* @param attribute
* Attribute.
*/
public void setAttribute(String attribute)
{
this.attribute = attribute;
}
/**
* Get attribute.
*
* @return Attribute.
*/
public String getAttribute()
{
return attribute;
}
/**
* Set Name. Same as setAttribute().
*
* @param value
* Attribute.
*/
public void setName(String value)
{
this.attribute = value;
}
/**
* Get Name. Set as getAttribute().
*
* @return Attribute.
*/
public String getName()
{
return attribute;
}
/**
* Set role.
*
* @param role
* The role the user must be in to store content.
*/
public void setRole(String role)
{
this.role = role;
}
/**
* Get role.
*
* @return Role.
*/
public String getRole()
{
return role;
}
/**
* Perform the test required for this particular tag, and either evaluate or
* skip the body of this tag.
*
* @exception JspException
* if a JSP exception occurs
*/
public int doStartTag() throws JspException
{
// Check role
if (role != null
&& !((HttpServletRequest) pageContext.getRequest())
.isUserInRole(role))
{
return SKIP_BODY;
} // end if
// Get context
ComponentContext compContext = (ComponentContext) pageContext
.getAttribute(ComponentConstants.COMPONENT_CONTEXT,
PageContext.REQUEST_SCOPE);
if (compContext == null)
throw new JspException(
"Error - tag.present : component context is not defined.
Check tag syntax");
Object value = compContext.getAttribute(attribute);
// The value is not null so present
if (value != null) return (EVAL_BODY_INCLUDE);
return (SKIP_BODY);
}
/**
* Evaluate the remainder of the current page normally.
*
* @exception JspException
* if a JSP exception occurs
*/
public int doEndTag() throws JspException
{
return (EVAL_PAGE);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org