org.apache.beehive.netui.tags.html
Class Anchor

Object
  extended by TagSupport
      extended by BodyTagSupport
          extended by AbstractClassicTag
              extended by HtmlBaseTag
                  extended by Anchor
All Implemented Interfaces:
Serializable, BodyTag, IterationTag, JspTag, Tag, HtmlConstants, URLParams, IAttributeConsumer, IHtmlAttrs, IHtmlCore, IHtmlEvents, IHtmlI18n, INetuiTag
Direct Known Subclasses:
ImageAnchor

public class Anchor
extends HtmlBaseTag
implements URLParams

Generates a URL-encoded hyperlink to a specified URI. Also adds support for URL re-writing and JavaScript-based form submission. An anchor must have one of five attributes to correctly create the hyperlink:

See Also:
Attribute, String, Serialized Form
Example
Submitting Form Data

In this sample, clicking on this anchor submits the form data and invokes the method submitForm.

      <netui:form action="formSubmit">
          Firstname:
          <netui:textBox dataSource="{actionForm.firstname}"/>
          Lastname:
          <netui:textBox dataSource="{actionForm.lastname}"/>
          <netui:anchor formSubmit="true">Submit</netui:anchor>
      </netui:form>

If the formSubmit attribute is set to true and no onClick attribute is set, the following JavaScript function will be written to the HTML page. This JavaScript function will be referenced by the onclick attribute of the generated anchor tag.

  function anchor_submit_form(netuiName, newAction)
  {
    for (var i=0; i<document.forms.length; i++) {
       if (document.forms[i].id == netuiName) {
          document.forms[i].method = "POST";
          document.forms[i].action = newAction;
          document.forms[i].submit();
       }
     }
  }

The JavaScript function will be invoked by the generated HTML anchor tag as follows:

 <a href="/WebApp/tagSamples/anchor/formSubmit.do" 
       onClick='anchor_submit_form("Netui_Form_0","/WebApp/tagSamples/anchor/formSubmit.do");return false;'>Submit</a>

Custom JavaScript Functions

It is possible to write a custom onClick JavaScript event handler that would do additional work, for example form validation, and still POST the form correctly. To accomplish this, add the custom JavaScript method to the page:

 function SubmitFromAnchor() 
 { 
   // implement custom logic here

   for(var i=0; i<document.forms.length; i++) 
   { 
     // submit to the action /aWebapp/formPost.do
     if (document.forms[i].action == "/aWebapp/formPost.do") 
     { 
       document.forms[i].method="POST"; 
       document.forms[i].action="/aWebapp/formPost.do"; 
       document.forms[i].submit(); 
     } 
   } 
 }
Then reference the JavaScript method from the <netui:anchor> tag:
 <netui:anchor formSubmit="true" onClick="SubmitFromAnchor(); return false;">Submit</netui:anchor>

Field Summary
protected  AnchorTag.State _state
           
 
Fields inherited from class HtmlBaseTag
JAVASCRIPT_STATUS
 
Fields inherited from class AbstractClassicTag
DefaultNamingChain, EMPTY_STRING, NETUI_UNIQUE_CNT
 
Fields inherited from class BodyTagSupport
bodyContent
 
Fields inherited from class TagSupport
id, pageContext
 
Fields inherited from interface HtmlConstants
ACCEPT, ACCESSKEY, ACTION, ALIGN, ALINK, ALT, ANCHOR, BACKGROUND, BASE, BGCOLOR, BODY, BORDER, BR, CAPTION, CELLPADDING, CELLSPACING, CHAR, CHAROFF, CHARSET, CHECKED, CLASS, COLS, COORDS, DIR, DISABLED, DIV, ENCTYPE, FOR, FORM, FORM_GET, FORM_POST, FRAME, HEIGHT, HREF, HREFLANG, HSPACE, HTML, ID, IMAGE, INPUT, INPUT_BUTTON, INPUT_CHECKBOX, INPUT_FILE, INPUT_HIDDEN, INPUT_IMAGE, INPUT_PASSWORD, INPUT_RADIO, INPUT_RESET, INPUT_SUBMIT, INPUT_TEXT, ISMAP, LABEL, LANG, LINK, LONGDESC, MAXLENGTH, METHOD, NAME, ONBLUR, ONCHANGE, ONCLICK, ONDBLCLICK, ONFOCUS, ONKEYDOWN, ONKEYPRESS, ONKEYUP, ONLOAD, ONMOUSEDOWN, ONMOUSEMOVE, ONMOUSEOUT, ONMOUSEOVER, ONMOUSEUP, ONRESET, ONSELECT, ONSUBMIT, ONUNLOAD, OPTION, READONLY, REL, REV, ROWS, RULES, SELECT, SHAPE, SIZE, SPAN, SRC, STYLE, SUMMARY, TABINDEX, TABLE, TARGET, TD, TEXT, TEXTAREA, TITLE, TR, TYPE, USEMAP, VALIGN, VALUE, VLINK, VSPACE, WIDTH
 
Fields inherited from interface BodyTag
EVAL_BODY_BUFFERED, EVAL_BODY_TAG
 
Fields inherited from interface IterationTag
EVAL_BODY_AGAIN
 
Fields inherited from interface Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
Anchor()
           
 
Method Summary
 void addParameter(String name, Object value)
          Adds a URL parameter to the generated hyperlink.
protected  boolean createAnchorBeginTag(StringBuilder results, StringBuilder script, TagRenderingBase trb)
          This method will create the <a> portion of an anchor.
 int doAfterBody()
          Save the body content of the Anchor.
 int doEndTag()
          Render the hyperlink.
 int doStartTag()
          Prepare the hyperlink for rendering
 AbstractHtmlState getState()
          This method will return the state associated with the tag.
 String getTagName()
          Returns the name of the Tag.
protected  void localRelease()
          Release any acquired resources.
 void setAccessKey(char accessKey)
          Sets the accessKey attribute value.
 void setAction(String action)
          Set the name of the action for the Anchor.
 void setAttribute(String name, String value, String facet)
          Base support for the attribute tag.
 void setCharSet(String charSet)
          Sets charset attribute for the anchor.
 void setClientAction(String action)
          Set a client action to run on the client.
 void setCoords(String coords)
          Sets coords attribute for the anchor.
 void setFormSubmit(boolean formSubmit)
          Sets the formSubmit indicator.
 void setHref(String href)
          Sets the href of the Anchor.
 void setHrefLang(String hreflang)
          Sets hreflang attribute for the anchor.
 void setLinkName(String linkName)
          Sets the link name of the Anchor.
 void setLocation(String location)
          Sets the anchor to be added to the end of the generated hyperlink.
 void setOnBlur(String onblur)
          Sets the onBlur javascript event.
 void setOnClick(String onclick)
          Sets the onClick javascript event.
 void setOnFocus(String onfocus)
          Sets the onFocus javascript event.
 void setRel(String rel)
          Sets rel attribute for the anchor.
 void setRev(String rev)
          Sets rev attribute for the anchor.
 void setScope(String scope)
          Set the name of the action for the Anchor.
 void setShape(String shape)
          Sets shape attribute for the anchor.
 void setTabindex(int tabindex)
          Sets the tabIndex of the rendered html tag.
 void setTarget(String target)
          Sets the window target.
 void setType(String type)
          Sets type attribute for the anchor.
 
Methods inherited from class HtmlBaseTag
addTagIdMapping, getJavaScriptAttribute, getNearestForm, getNearestIdWriter, getOnClick, getTagId, isIdTransparency, qualifyUrlToContext, renderTagId, setDir, setLang, setOnDblClick, setOnKeyDown, setOnKeyPress, setOnKeyUp, setOnMouseDown, setOnMouseMove, setOnMouseOut, setOnMouseOver, setOnMouseUp, setStateAttribute, setStyle, setStyleClass, setTagId, setTitle
 
Methods inherited from class AbstractClassicTag
applyNamingChain, getErrorsReport, getNamingChain, getNextId, getScriptReporter, getUserLocale, hasErrors, qualifyAttribute, registerTagError, registerTagError, renderAttribute, reportAndExit, reportErrors, rewriteName, setNonEmptyValueAttribute, setRequiredValueAttribute, write
 
Methods inherited from class BodyTagSupport
doInitBody, getBodyContent, getPreviousOut, release, setBodyContent
 
Methods inherited from class TagSupport
findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface Tag
getParent, setPageContext, setParent
 

Field Detail

_state

protected AnchorTag.State _state
Constructor Detail

Anchor

public Anchor()
Method Detail

getTagName

public String getTagName()
Returns the name of the Tag.

Specified by:
getTagName in interface INetuiTag
Specified by:
getTagName in class AbstractClassicTag
Returns:
the name of the tag.

getState

public AbstractHtmlState getState()
This method will return the state associated with the tag. This is used by this base class to access the individual state objects created by the tags.

Specified by:
getState in class HtmlBaseTag
Returns:
a subclass of the AbstractHtmlState class.

setAttribute

public void setAttribute(String name,
                         String value,
                         String facet)
                  throws JspException
Base support for the attribute tag. This is overridden to prevent setting the href attribute.

Specified by:
setAttribute in interface IAttributeConsumer
Overrides:
setAttribute in class HtmlBaseTag
Parameters:
name - The name of the attribute. This value may not be null or the empty string.
value - The value of the attribute. This may contain an expression.
facet - The name of a facet to which the attribute will be applied. This is optional.
Throws:
JspException - A JspException may be thrown if there is an error setting the attribute.

setAction

public void setAction(String action)
               throws JspException
Set the name of the action for the Anchor.

Parameters:
action - - the name of the action to set for the Anchor. Action requires a value.
Throws:
JspException

setScope

public void setScope(String scope)
Set the name of the action for the Anchor.

Parameters:
scope - - the name of the action to set for the Anchor

setFormSubmit

public void setFormSubmit(boolean formSubmit)
Sets the formSubmit indicator.

Parameters:
formSubmit - - whether or not the enclosing Form should be submitted.

setOnClick

public void setOnClick(String onclick)
Sets the onClick javascript event.

Specified by:
setOnClick in interface IHtmlEvents
Overrides:
setOnClick in class HtmlBaseTag
Parameters:
onclick - - the onClick event.

setTabindex

public void setTabindex(int tabindex)
Sets the tabIndex of the rendered html tag.

Parameters:
tabindex - - the tab index.

setHref

public void setHref(String href)
             throws JspException
Sets the href of the Anchor. This attribute will accept the empty String as a legal value.

Parameters:
href - - the hyperlink URI for the Anchor.
Throws:
JspException

setClientAction

public void setClientAction(String action)
                     throws JspException
Set a client action to run on the client. When set on an anchor, a NetUI JavaScript action will be run. This attribute may not be set if href or action is set.

Parameters:
action - an action to run on the client.
Throws:
JspException

setLinkName

public void setLinkName(String linkName)
                 throws JspException
Sets the link name of the Anchor.

Parameters:
linkName - - the link name for the Anchor.
Throws:
JspException

setLocation

public void setLocation(String location)
Sets the anchor to be added to the end of the generated hyperlink.

Parameters:
location - - the name of the location anchor.

setCharSet

public void setCharSet(String charSet)
Sets charset attribute for the anchor.

Parameters:
charSet - - the window target.

setType

public void setType(String type)
Sets type attribute for the anchor.

Parameters:
type - - the window target.

setHrefLang

public void setHrefLang(String hreflang)
Sets hreflang attribute for the anchor.

Parameters:
hreflang - - the window target.

setRel

public void setRel(String rel)
Sets rel attribute for the anchor.

Parameters:
rel - - the window target.

setRev

public void setRev(String rev)
Sets rev attribute for the anchor.

Parameters:
rev - - the window target.

setShape

public void setShape(String shape)
Sets shape attribute for the anchor.

Parameters:
shape - - the window target.

setCoords

public void setCoords(String coords)
Sets coords attribute for the anchor.

Parameters:
coords - - the window target.

setTarget

public void setTarget(String target)
Sets the window target.

Parameters:
target - - the window target.

addParameter

public void addParameter(String name,
                         Object value)
                  throws JspException
Adds a URL parameter to the generated hyperlink.

Specified by:
addParameter in interface URLParams
Parameters:
name - - the name of the parameter to be added.
value - - the value of the parameter to be added (a String or String[]).
Throws:
JspException

doStartTag

public int doStartTag()
               throws JspException
Prepare the hyperlink for rendering

Specified by:
doStartTag in interface Tag
Overrides:
doStartTag in class BodyTagSupport
Throws:
JspException - if a JSP exception has occurred

doAfterBody

public int doAfterBody()
                throws JspException
Save the body content of the Anchor.

Specified by:
doAfterBody in interface IterationTag
Overrides:
doAfterBody in class BodyTagSupport
Throws:
JspException - if a JSP exception has occurred

doEndTag

public int doEndTag()
             throws JspException
Render the hyperlink.

Specified by:
doEndTag in interface Tag
Overrides:
doEndTag in class BodyTagSupport
Throws:
JspException - if a JSP exception has occurred

createAnchorBeginTag

protected final boolean createAnchorBeginTag(StringBuilder results,
                                             StringBuilder script,
                                             TagRenderingBase trb)
                                      throws JspException
This method will create the <a> portion of an anchor. It is called by subclasses, for example, the ImageAnchor relies on this code to generate the <a>.

Parameters:
results - a StringBuffer to write the anchor into
script - a StringBuffer that will contain any JavaScript that may need to be added to the generated HTML response.
Returns:
a boolean value indicating if an error occur creating the anchor.
Throws:
JspException

localRelease

protected void localRelease()
Release any acquired resources.

Overrides:
localRelease in class HtmlBaseTag

setAccessKey

public void setAccessKey(char accessKey)
Sets the accessKey attribute value. This should key value of the keyboard navigation key. It is recommended not to use the following values because there are often used by browsers A, C, E, F, G, H, V, left arrow, and right arrow.

Parameters:
accessKey - - the accessKey value.

setOnBlur

public void setOnBlur(String onblur)
Sets the onBlur javascript event.

Parameters:
onblur - - the onBlur event.

setOnFocus

public void setOnFocus(String onfocus)
Sets the onFocus javascript event.

Parameters:
onfocus - - the onFocus event.