|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
ObjectTagSupport
BodyTagSupport
AbstractClassicTag
HtmlBaseTag
AnchorBase
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 the following 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 |
|---|
| Fields inherited from class AnchorBase |
|---|
_clientAction, _linkName, _state, REQUIRED_ATTR |
| 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 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, renderDefaultNameAndId, renderNameAndId, setDir, setLang, setOnDblClick, setOnKeyDown, setOnKeyPress, setOnKeyUp, setOnMouseDown, setOnMouseMove, setOnMouseOut, setOnMouseOver, setOnMouseUp, setStateAttribute, setStyle, setStyleClass, setTagId, setTitle |
| 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 |
|---|
public Anchor()
| Method Detail |
|---|
public String getTagName()
getTagName in interface INetuiTaggetTagName in class AbstractClassicTagpublic AbstractHtmlState getState()
getState in class HtmlBaseTagAbstractHtmlState class.public void setOnClick(String onclick)
setOnClick in interface IHtmlEventssetOnClick in class HtmlBaseTagonclick - the onClick event.
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.
JspExceptionpublic 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 setTarget(String target)
target - the window target.public void setValue(String value)
value - the text of the anchor.
public int doStartTag()
throws JspException
doStartTag in interface TagdoStartTag in class BodyTagSupportJspException - if a JSP exception has occurred
public int doAfterBody()
throws JspException
doAfterBody in interface IterationTagdoAfterBody in class BodyTagSupportJspException - if a JSP exception has occurred
public int doEndTag()
throws JspException
doEndTag in interface TagdoEndTag in class BodyTagSupportJspException - if a JSP exception has occurred
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||