You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Duggal, Sanjay" <sa...@cgey.com> on 2003/12/31 13:33:45 UTC

Custom Link Tag

Hi,

I am writing a custom tag: MyLinkTag that extends the
org.apache.struts.taglib.html.LinkTag.

MyLinkTag has two fields. They are 
showAlways : Boolean & alternateLink : String. 

The functionality of the MyLinkTag is captured in the following code
snippet:
****************************************************************************
*******
HttpServletRequest request = pageContext.getRequest();
ActionMappings actionMappings =
(ActionMappings)request.getAttribute(Action.MAPPINGS_KEY); 
String path = getHref();
ActionMapping actionMapping = actionMappings.findMapping(path);
String[] roleNames = actionMapping.getRoleNames();
boolean userInRole = false;
for(int i=0; i<roleNames.length(); i++)
{
	userInRole = request.isUserInRole(roleNames);
	if(!userInRole){
		if((alternateLink != null) && !("".equals(alternateLink))){
			setHref(alternateLink);
		}
		else{
			if(showAlways){
				setDisabled(true);
			}
			else{
				//don't show the link
				return SKIP_BODY;
			}
		}
	}//end if !userInRole
}//end for loop
****************************************************************************
*******

The problem is I don't know where to place this code i.e. in which method:
doStartTag() or doEndTag() or doAfterBody() or any other?? 
What method should I override??
And what should be the return [integer] values?? 

Thanks in advance.
Sanjay

____________________________________________________
This message contains information that may be privileged or confidential and
is the property of the Cap Gemini Ernst & Young Group. It is intended only
for the person to whom it is addressed. If you are not the intended
recipient, you are not authorised to read, print, retain, copy, disseminate,
distribute, or use this message or any part thereof. If you receive this
message in error, please notify the sender immediately and delete all copies
of this message.

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Custom Link Tag

Posted by Nicolas De Loof <ni...@cgey.com>.
Place your code in doStartTag as it can return SKIP_BODY to exclude body from resulting HTML.

return EVAL_BODY_INCLUDE if you want the body to be included

Nico.

> Hi,
> 
> I am writing a custom tag: MyLinkTag that extends the
> org.apache.struts.taglib.html.LinkTag.
> 
> MyLinkTag has two fields. They are 
> showAlways : Boolean & alternateLink : String. 
> 
> The functionality of the MyLinkTag is captured in the following code
> snippet:
> ****************************************************************************
> *******
> HttpServletRequest request = pageContext.getRequest();
> ActionMappings actionMappings =
> (ActionMappings)request.getAttribute(Action.MAPPINGS_KEY); 
> String path = getHref();
> ActionMapping actionMapping = actionMappings.findMapping(path);
> String[] roleNames = actionMapping.getRoleNames();
> boolean userInRole = false;
> for(int i=0; i<roleNames.length(); i++)
> {
> userInRole = request.isUserInRole(roleNames);
> if(!userInRole){
> if((alternateLink != null) && !("".equals(alternateLink))){
> setHref(alternateLink);
> }
> else{
> if(showAlways){
> setDisabled(true);
> }
> else{
> //don't show the link
> return SKIP_BODY;
> }
> }
> }//end if !userInRole
> }//end for loop
> ****************************************************************************
> *******
> 
> The problem is I don't know where to place this code i.e. in which method:
> doStartTag() or doEndTag() or doAfterBody() or any other?? 
> What method should I override??
> And what should be the return [integer] values?? 
> 
> Thanks in advance.
> Sanjay
> 
> ____________________________________________________
> This message contains information that may be privileged or confidential and
> is the property of the Cap Gemini Ernst & Young Group. It is intended only
> for the person to whom it is addressed. If you are not the intended
> recipient, you are not authorised to read, print, retain, copy, disseminate,
> distribute, or use this message or any part thereof. If you receive this
> message in error, please notify the sender immediately and delete all copies
> of this message.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org