Composum Taglibs - Nodes Taglib (cpn)

Composum Nodes Taglib (cpn)

These are general tags contained in Composum Nodes that can be used in rendering pages and dialogs, and are used widely in the various parts of the Composum Platform itself.

anchor

Embeds an anchor link tag

Attributes

  • name
    String
    optional
    default: a

    if set, this is used instead of tag name 'a'.

  • classes
    java.lang.String
    optional

    deprecated: use 'class' like a normal HTML tag

  • test
    String
    optional

    an EL expression that determines whether the tag is shown

Examples

  • <cpn:anchor test="${not empty model.anchor}" 
        name="${model.anchor}" title="${model.title}"/>

    Renders an anchor with the name given by model.anchor , if that is not empty. The title attribute is a dynamic attribute - it has no special function in the tag, but is just rendered into the output.

bundle

Declares the topmost resource bundle for i18n translation in the current requests resource bundle stack.

Attributes

  • basename
    String
    mandatory

    the Java Resource Bundle base name

Examples

  • <cpn:bundle basename="ist-composum-site"/>

    selects the Resource Bundle with the base name 'ist-composum-site' as the topmost resource bundle in the requests processing; this resource bundle is now the first in the chain for translations

clientlib

Includes a clientlib reference (JS, CSS etc).

Client libraries are folders of sling:resourceType composum/nodes/commons/clientlib containing subfolders for each type, and declare dependencies to other client libraries. The tag can reference multiple client libraries if they are referenced by category, and if the client library/-ies have dependencies to other client libraries / resources. Thus, the tag can render as several link / script / img tags.

see: Clientlibs

Attributes

  • test
    Boolean
    optional
    default: true

    nothing is rendered if the test attribute value is ‚false‘ (general condition)

  • category
    String
    optional

    the category of client library to be included; one of category or path is required but categories are preferred and more flexible

  • path
    String
    optional

    the repository path to reference the client library to be included; one of category or path is required

  • type
    String
    optional
    default: link

    type of rendered resources: css, js, link, img, png, jpg

Examples

  • <cpn:clientlib type="link" category="${model.viewClientlibCategory}"/> 
    <cpn:clientlib type="css" category="${model.viewClientlibCategory}"/> 
    <cpn:clientlib type="css" test="${model.editMode}" category="${model.editClientlibCategory}"/>

    a typical HTML head snippet to include header link tags ans styles; the edit mode styles are included only if the 'editMode' check returns 'true'

  • <cpn:clientlib type="js" category="${model.viewClientlibCategory}"/> 
    <cpn:clientlib type="js" test="${model.editMode}" category="${model.editClientlibCategory}"/> 
    

    the analogous example for the include of clientlib JS code - typically at the end of the HTML body

component

Creates a JSP / Java variable of an instance of a Java Bean class (model class). The variable is declared only in the body of the component tag. Each variable of the same name in the specified scope if hided during tag processing and restored on the tags end.

Attributes

  • var
    String
    mandatory

    the name of the variable; this name must be unique in the declared scope

  • type
    String
    mandatory

    the complete class name of the Java class of the instance to create

  • scope
    String
    optional
    default: page

    the scope of the variable declaration; the variable is declared inside of the component tag body and in this specified scope.

    • page: JSP page scope (default)
    • request: available in the page and all included components
    • session: the variable is available during session lifetime

    In each case the availability of the variable is limited by the tag boundaries.

  • replace
    Boolean
    optional

    If 'true' a new instance is created and set as variable. If 'false' the variable is created only of not existing in the specified scope and reused if always available with a compatible type.

    In the 'page' scope the default is 'true' otherwise 'false'. So you can declare a variable in request scope for a set of components in the include tree which is declared in each component which needs this and shared nevertheless independently from the creating script.

Examples

  • <cpn:component var="model" type="my.project.model.ComponentModel"> 
        <cpn:text value="${model.description}"/> 
        ... 
    </cpn:component> 
    <%-- 'model' not available outside the component tag --%>

    Provides an instance of the specified type as variable 'model' in the page scope.

  • <cpn:component var="model" type="my.project.model.ComponentModel" scope="request"> 
        <sling:include path="child"/> 
    </cpn:component> 
    

    The declared variable 'model' is also available in the script code of the included component. If the script of the included component declares the the variable 'model' also in request scope and of the same type (and without 'replace="true"') the instance declared here and its current state is shared with the 'child' component.

defineObjects

An extension of the sling:defineObjects tag.

Examples

  • <cpn:defineObjects/>

    Creates additional variables:

    • pagesAccessAuthor , pagesAccessPreview , pagesAccessPublic : boolean variables that are true if the request runs in access mode author / preview / public , respectively.
    • pagesModeNone, pagesModePreview, pagesModeEdit, pagesModeDevelop : boolean variables that are true if the request runs in display mode none, preview, edit or develop, respectively. 

div

The ‚div‘ tag is rendering a HTML div tag if the condition (‚test’ attribute) is ‚true‘. 

Attributes

  • test
    Boolean
    optional
    default: true

    nothing (exception: the ‚body‘ is ‚true‘) is rendered if the test attribute value is ‚false‘ (general condition)

  • body
    Boolean
    optional
    default: false

    if the ‚body‘ condition is true the tags body is rendered even if the general ‚test‘ condition is ‚false’ - the 'conditional tag around' case

  • tagName
    String
    optional
    default: div

    the HTML tag name; if ‚none‘ no tag is rendered around the body

  • class
    String
    optional

    the CSS class attribute of the HTML tag

  • ...
    Object
    optional

    each dynamic attribute with a non null value is rendered as it is in the HTML tag

Examples

  • <cpn:div test="${model.divAround}" body="true" class="div-around"> 
        ... 
    </cpn:div>

    Is rendering the 'div' tag if the 'model.isDivAround()'  returns 'true'; the body is rendered always even if the 'test' condition is not true.

  • <cpn:div test="${model.notEmpty}" class="...">...</cpn:div>

    Is rendering the div tag and its body only if the 'model.isNotEmpty()' method returns 'true'.

form

Generates form elements with mapped action URLs

Attributes

  • action
    String
    mandatory

    the action URL to send the form data; this URL is mapped (resolver.map()) automatically

  • method
    String
    optional

    the HTTP method of the form request

  • enctype
    String
    optional

    the encoding type of the form request data set ('enctype' attribute of the HTML form tag)

  • charset
    String
    optional

    the value of the HTML form 'accept-charset' attribute

  • test
    String
    optional

    nothing is rendered if the test attribute value is ‚false‘ (general condition)

  • ...
    Object
    optional

    each dynamic attribute with a non null value is rendered as it is in the HTML tag

Examples

  • <cpn:image classes="${fileCssBase}_image" src="${file.path}" draggable="false"/>

    renders a HTML anchor tag to the resource path with additional tag attributes; the resources path is mapped automatically

image

Rendering of an image HTML tag with resolver mapping of the image URL.

Attributes

  • test
    Boolean
    optional
    default: true

    nothing (exception: the ‚body‘ is ‚true‘) is rendered if the test attribute value is ‚false‘ (general condition)

  • src
    String
    mandatory

    the image URL / URI / path; an external URL is rendered as it is a path or URI is mapped using the Sling resource resolver

  • map
    Boolean
    optional

    the on/off switch for the resolver mapping

  • format
    String
    optional

    an optional format rule to prepare the URL before rendering; useful for example if a resource path in the 'src' attribute should be embedded in a service URL

  • class
    String
    optional

    the CSS class attribute of the HTML tag

  • ...
    Object
    optional

    each dynamic attribute with a non null value is rendered as it is in the HTML tag

Rendering of an anchor HTML tag (hyperlink) this resolver mapping of the link URL ('href' attribute).

Attributes

  • test
    Boolean
    optional
    default: true

    nothing (exception: the ‚body‘ is ‚true‘) is rendered if the test attribute value is ‚false‘ (general condition)

  • body
    Boolean
    optional
    default: false

    if the ‚body‘ condition is true the tags body is rendered even if the general ‚test‘ condition is ‚false’ - the 'conditional link around' case

  • href
    String
    mandatory

    the target URL / URI / path; an external URL is rendered as it is, a path or URI is mapped using the Sling resource resolver

  • map
    Boolean
    optional

    the on/off switch for the resolver mapping

  • format
    String
    optional

    an optional format rule to prepare the URL before rendering; useful for example if a resource path in the 'href' attribute should be embedded in a service URL

  • class
    String
    optional

    the CSS class attribute of the HTML tag

  • ...
    Object
    optional

    each dynamic attribute with a non null value is rendered as it is in the HTML tag

Examples

  • <cpn:link href="${target}" format="/bin/pages.html{}">${cpn:path(target)}</cpn:link>

    Renders a link to a page resource for editing with the 'Pages' editor.

  • <cpn:link test="${condition}" body="true" href="${target}"> 
        <div class="...">...</div> 
    </cpn:link>

    a conditional link around a 'div'; the body (the 'div' inside of the tag) is always rendered but the link around only if condition is 'true'

text

The ‚text‘ tag ist the general tag to embed text values in the HTML output. The value is normally escaped to prevent from XSS attacks. If the value is empty (or null) nothing is rendered. It’s possible to format the value before escaping and rendering.

Attributes

  • test
    Boolean
    optional
    default: true

    nothing is rendered if the test attribute value is ‚false‘ (general condition)

  • escape
    Boolean
    optional
    default: true

    the general on/off switch for text escaping

  • type
    String
    optional
    default: text

    the text type to select the escape rule:

    • text: HTML text escaping (default)
    • rich: rich text escaping (text formatting and simple HTML tags allowed)
    • path: repository path (URI) encoding
    • script: ECMA script escaping
    • style: CSS code escaping
    • cdata: wrap value with
    • value: no escaping!
  • value
    Object
    optional

    the text value to render; if not present the 'property' attribute is used

  • property
    String
    optional

    the name of a property of the current resource to retrieve the text value; used if no value attribute is specified; if no value found and no property declared the text tag body content is rendered as text (without formatting)

  • format
    String
    optional

    format pattern string ‚{fmt-type}..format..‘ to prepare the text value with {fmt-type}:

    • {Message}: a Message text formatter is used
    • {Date}: a SimpleDateFormat formatier is used
    • {String}: a string formatter is used
    • {Log} (or nothing and at least one ‚{}‘ pattern in the format): a Log formatter is used
  • i18n
    Boolean
    optional

    if ‚true‘ the text value is translated using the requests locale and the requests resource bundle stack; if a format is specified the format is translated before formatting - in this case the value is translated separately before formatting

  • locale
    Object
    optional
    default: the requests locale

    the locale to use to create the formatter for the specified format

  • tagName
    String
    optional
    default: div

    the HTML tag name; if ‚none‘ no tag is rendered around the value

  • class
    String
    optional

    the CSS class attribute of the HTML tag

  • ...
    Object
    optional

    each dynamic attribute with a non null value is rendered as it is in the HTML tag

Examples

  • <cpn:text value="${model.title}"/>

    a simple text rendering example (escaped as HTML text)

  • <cpn:text property="stringValue" format="{String}a string: '%s'" i18n="true"/>

    a formatted text value rendering; if stringValue is not empty the text is rendered with HTML escaping embedded in the format string; the format and the value are translated before formatting if a matching translation can be found