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

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

public class Anchor
extends AnchorBase

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
 
Fields inherited from class AnchorBase
_clientAction, _linkName, _state
 
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
ABBR, ACCEPT, ACCESSKEY, ACTION, ALIGN, ALINK, ALT, ANCHOR, AREA, AXIS, BACKGROUND, BASE, BGCOLOR, BODY, BORDER, BR, CAPTION, CELLPADDING, CELLSPACING, CHAR, CHAROFF, CHARSET, CHECKED, CLASS, COLS, COLSPAN, COORDS, DIR, DISABLED, DIV, ENCTYPE, FOR, FORM, FORM_GET, FORM_POST, FRAME, HEADERS, 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, LANGUAGE, 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, ROWSPAN, RULES, SCOPE, SCRIPT, SELECT, SHAPE, SIZE, SPAN, SRC, STYLE, SUMMARY, TABINDEX, TABLE, TARGET, TBODY, TD, TEXT, TEXTAREA, TFOOT, TH, THEAD, 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
 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.
 void setCharSet(String charSet)
          Sets charset attribute for the anchor.
 void setClientAction(String action)
          Set a client action to run on the client.
 void setHrefLang(String hreflang)
          Sets hreflang attribute for the anchor.
 void setLinkName(String linkName)
          Sets the link name of the Anchor.
 void setOnClick(String onclick)
          Sets the onClick javascript event.
 void setRel(String rel)
          Sets rel attribute for the anchor.
 void setRev(String rev)
          Sets rev attribute for the anchor.
 void setTarget(String target)
          Sets the window target.
 void setType(String type)
          Sets type attribute for the anchor.
 void setValue(String value)
          This will set the text of the anchor.
 
Methods inherited from class AnchorBase
addParameter, createAnchorBeginTag, getPopupSupport, localRelease, setAccessKey, setAction, setAttribute, setCoords, setDisableSecondClick, setFormSubmit, setHref, setLocation, setOnBlur, setOnFocus, setPopup, setShape, setTabindex, setTargetScope
 
Methods inherited from class HtmlBaseTag
getJavaScriptAttribute, getNearestForm, getOnClick, getTagId, qualifyUrlToContext, renderDefaultNameAndId, renderNameAndId, setDir, setLang, setOnDblClick, setOnKeyDown, setOnKeyPress, setOnKeyUp, setOnMouseDown, setOnMouseMove, setOnMouseOut, setOnMouseOver, setOnMouseUp, setStateAttribute, setStyle, setStyleClass, setTagId, setTitle
 
Methods inherited from class AbstractClassicTag
applyNamingChain, getErrorsReport, getIdForTagId, getNamingChain, getNextId, getScriptReporter, getUserLocale, hasErrors, qualifyAttribute, registerTagError, registerTagError, 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
 

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.

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.

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. The link name is treated as a fragment identifier and may or may not contain the "#" character. If it does, the link name will not be qualified into a ScriptContainer. If the link name does not contain the "#" the normal tagId qualification will take place to produce the actual fragment identifier.

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

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.

setTarget

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

Parameters:
target - - the window target.

setValue

public void setValue(String value)
This will set the text of the anchor. If there is body content, this will override that value.

Parameters:
value - - The text of the anchor.

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