public class LinkToTag extends FreeMarkerTag
<@link_to ... />
tag.
This tag generates an HTML anchor tag and is capable of regular HTML links, as well as Ajax capability.
Please, see below for attributes and their usage.
/admin/permissions
where "admin" is a
sub-package and "permissions" is a name of a controller. In this example, the controller class name would be:
app.controllers.admin.PermissionsController
. If a controller path is specified, the preceding slash is mandatory.
Optionally this could be a name of a controller from a default package: "permissions", and in this case,
the controller class name is expected to be app.controllers.PermissionsController
.
If a name of controller is specified, the preceding slash can be omitted.
This attribute is optional. If this attribute is omitted, the
tag will use the controller which was used to generate the current page. This makes it convenient to write links on pages
for the same controller.
<@link_to controller="books" action="fetch">Get Books</@>
This will generate a simple non-Ajax link
<@link_to controller="books" action="fetch" destination="result" >Get Books</@>
This will generate a simple Ajax link. The method by default is GET. After Ajax call, the result will be inserted
into an element with ID: "result", similar to: <div id="result"></div>
<@link_to controller="books" id="123"
method="delete" before="beforeDelete" after="afterDelete"
confirm="Are you really sure you want to delete this book?">Delete Book</@>
function beforeDelete(beforeArg){
.....
}
function afterDelete(afterArg, data){
...
}
Here, the JS confirmation dialog will present the message before posting an Ajax call, then function "beforeDelete"
will be called. After that, it will make an Ajax call, and will execute function "afterDelete", passing it the
result of Ajax invocation as an argument. In the JS code above, the "beforeArg" and "afterArg" arguments have values
null since the "before_arg" and "after_arg" attributes were not used.
<@link_to controller="books" action="fetch" before="doBeforeWithArg" before_arg="books_result"
after="doAfterWithArg" after_arg="books_result">Get Books</@>
This code expects to find JS functions similar to these:
function doBeforeWithArg(elm){
$("#" + elm).html("wait...");
}
function doAfterWithArg(elm, data){
$("#" + elm).html(data);
}
This is presuming that there is an element like this on the page:
<div id="books_result"></div>
In this example, the "books_result" string is passed as argument to "doBeforeWithArg" as only one argument and the
same is passed as a first argument to function "doAfterWithArg". The second argument to the "doAfterWithArg" is a
result of Ajax invocation (presumably HTML representing books generated from some partial).
<@link_to controller="books" action="doesnotexist" error="onError" destination="callbacks_result">Will cause error</@>
function onError(status, responseText){
alert("Got error, status: " + status + ", Response: " + responseText);
}
In this example, the link is trying to make an Ajax call to a controlled action which does not exists.
<@link_to data="data-greeting='hola' data-bye='astalavista'" ... >
LOGGER
Constructor and Description |
---|
LinkToTag() |
Modifier and Type | Method and Description |
---|---|
protected void |
render(Map params,
String body,
Writer writer)
Implement this method ina concrete subclass.
|
execute, get, getAllVariables, getContextPath, getUnwrapped, getUnwrapped, logger, overrideContext, process, session, sessionObject, validateParamsPresence
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
appContext, context, cookie, cookies, cookieValue, exists, format, getId, getLocale, getRequestHost, getRequestPort, getRequestProperties, getRequestProtocol, getRoute, header, headers, host, ipAddress, ipForwardedFor, isDelete, isGet, isHead, isMethod, isMultipartContent, isPost, isPut, isXhr, locale, method, param, param, params, params, params, params1st, params1st, path, port, protocol, queryString, remoteAddress, remoteHost, requestHas, servletPath, session, session, uri, url, userAgent, xhr
protected void render(Map params, String body, Writer writer) throws Exception
FreeMarkerTag
render
in class FreeMarkerTag
params
- this is a list of parameters as provided to tag in HTML.body
- body of tagwriter
- writer to write output to.Exception
- if anyCopyright © 2021 JavaLite. All rights reserved.