|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectTagSupport
BodyTagSupport
AbstractClassicTag
HtmlBaseTag
Anchor
public class Anchor
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:
Attribute
,
String
,
Serialized FormIn 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 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 |
---|
protected AnchorTag.State _state
Constructor Detail |
---|
public Anchor()
Method Detail |
---|
public String getTagName()
getTagName
in interface INetuiTag
getTagName
in class AbstractClassicTag
public AbstractHtmlState getState()
getState
in class HtmlBaseTag
AbstractHtmlState
class.public void setAttribute(String name, String value, String facet) throws JspException
href
attribute.
setAttribute
in interface IAttributeConsumer
setAttribute
in class HtmlBaseTag
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.
JspException
- A JspException may be thrown if there is an error setting the attribute.public void setAction(String action) throws JspException
action
- - the name of the action to set for the Anchor. Action requires a value.
JspException
public void setScope(String scope)
scope
- - the name of the action to set for the Anchorpublic void setFormSubmit(boolean formSubmit)
formSubmit
- - whether or not the enclosing Form should be submitted.public void setOnClick(String onclick)
setOnClick
in interface IHtmlEvents
setOnClick
in class HtmlBaseTag
onclick
- - the onClick event.public void setTabindex(int tabindex)
tabindex
- - the tab index.public void setHref(String href) throws JspException
href
- - the hyperlink URI for the Anchor.
JspException
public void setClientAction(String action) throws JspException
href
or action
is set.
action
- an action to run on the client.
JspException
public void setLinkName(String linkName) throws JspException
linkName
- - the link name for the Anchor.
JspException
public void setLocation(String location)
location
- - the name of the location anchor.public void setCharSet(String charSet)
charset
attribute for the anchor.
charSet
- - the window target.public void setType(String type)
type
attribute for the anchor.
type
- - the window target.public void setHrefLang(String hreflang)
hreflang
attribute for the anchor.
hreflang
- - the window target.public void setRel(String rel)
rel
attribute for the anchor.
rel
- - the window target.public void setRev(String rev)
rev
attribute for the anchor.
rev
- - the window target.public void setShape(String shape)
shape
attribute for the anchor.
shape
- - the window target.public void setCoords(String coords)
coords
attribute for the anchor.
coords
- - the window target.public void setTarget(String target)
target
- - the window target.public void addParameter(String name, Object value) throws JspException
addParameter
in interface URLParams
name
- - the name of the parameter to be added.value
- - the value of the parameter to be added (a String or String[]).
JspException
public int doStartTag() throws JspException
doStartTag
in interface Tag
doStartTag
in class BodyTagSupport
JspException
- if a JSP exception has occurredpublic int doAfterBody() throws JspException
doAfterBody
in interface IterationTag
doAfterBody
in class BodyTagSupport
JspException
- if a JSP exception has occurredpublic int doEndTag() throws JspException
doEndTag
in interface Tag
doEndTag
in class BodyTagSupport
JspException
- if a JSP exception has occurredprotected final boolean createAnchorBeginTag(StringBuilder results, StringBuilder script, TagRenderingBase trb) throws JspException
ImageAnchor
relies on this code to generate the <a>.
results
- a StringBuffer to write the anchor intoscript
- 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
protected void localRelease()
localRelease
in class HtmlBaseTag
public void setAccessKey(char accessKey)
A, C, E, F, G,
H, V, left arrow, and right arrow
.
accessKey
- - the accessKey value.public void setOnBlur(String onblur)
onblur
- - the onBlur event.public void setOnFocus(String onfocus)
onfocus
- - the onFocus event.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |