Copyright© 2008-2018 SiteVision AB, all rights reserved.
@Requireable(value="UserFieldRenderer") public interface UserFieldRenderer
An instance of the SiteVision class implementing this interface can be obtained via Utils.getUserFieldRenderer()
.
See Utils
for how to obtain an instance of the Utils
interface.
Using the UserFieldRenderer is pretty straightforward, if you remember that it is stateful and that the previously loaded user identity node will be cleared whenever you try to load a new one. Conceptually you would typically use it like this:
You can then re-use the UserFieldRenderer for another user identity until you are done. Something like:
Example of how this strategy could be implemented in Velocity:
(You want to do a simple listing of the user fields "Namn" and "E-postadress" for some user identities or users in $myList)
## Get UserFieldRenderer
#set ($userFieldRenderer = $sitevisionUtils.userFieldRenderer)
## Ensure at least one of the fields actually exist
#if ($userFieldRenderer.isValidFieldName('Namn') || $userFieldRenderer.isValidFieldName('E-postadress'))
## Iterate through the list and render fields for all valid nodes
<ul class="sv-no-list-style">
#foreach ($item in $myList)
## Check if this node can be rendered
#if ($userFieldRenderer.isRenderable($item))
## Update the renderer and render
$userFieldRenderer.update($item)
<li>
$userFieldRenderer.render('Namn')
$userFieldRenderer.render('E-postadress')
</li>
#end
#end
</ul>
#end
Important rendering note! When rendering a user field value, you must specify the name
of the user field. See isValidFieldName(String)
for more information about how names are matched to user fields.
Modifier and Type | Method and Description |
---|---|
String |
getPlainUserFieldValueAsHtml(String aPlainUserFieldValue)
Returns a plain text user field value as html.
|
boolean |
isLoaded()
Whether or not this renderer contains a user identity.
|
boolean |
isRenderable(Node aNode)
Helper method to check if a certain node can be rendered.
|
boolean |
isValidFieldName(String aUserFieldName)
Helper method to check if a named user field is available.
|
String |
render(String aUserFieldName)
Returns the value as html for a named user field for currently loaded user identity.
|
String |
renderPlain(String aUserFieldName)
Returns the value as plain text for a named user field for currently loaded user identity.
|
void |
update(Node aUserIdentity)
Updates the renderer with a new user identity node.
|
void update(Node aUserIdentity)
If aUserIdentity
is not a renderable node, the argument will be considered as null
, i.e.
the renderer will not have any renderable node in subsequent render execution.
aUserIdentity
- a user identity node, or a user that has an identity on current siteboolean isLoaded()
true
if a renderable node is loaded, false
if not.boolean isRenderable(Node aNode)
Nodes with the following primary node types are potentially renderable:
sv:userIdentity
sv:user
(non-anonymous) » will be renderable if a sv:userIdentity can be extractedsv:simpleUser
» will be renderable if a sv:userIdentity can be extractedsv:systemUser
» will be renderable if a sv:userIdentity can be extractedaNode
- the node to checktrue
if aNode
is supported by this renderer, false
if notboolean isValidFieldName(String aUserFieldName)
An important note about field names and user field lookup! A specific user field can be found via multiple names:
First found match is used!
This is a convenience to make user fields easier to find, but beware of colliding names! For instance, if field A has Ldap name "X" and field B has UI name "X" - field B will be used.
aUserFieldName
- the name of the user fieldtrue
if current site has a user field that can be found via aUserFieldName
, false
if notString render(String aUserFieldName)
The rendered output of the user field value is handled as:
EndecUtil.escapeXML(String)
)EndecUtil.br(String)
)OutputUtil.getHyperlinkedText(String)
)
Note! The result of this method is equivalent with calling getPlainUserFieldValueAsHtml(String)
with the
result of the renderPlain(String)
method, but this method is more efficient and should always be preferred.
aUserFieldName
- the name of the user field, see: isValidFieldName(String)
null
.String renderPlain(String aUserFieldName)
Note! The rendered output is plain text and must be escaped if it should be part of the html output of a page!
aUserFieldName
- the name of the user field, see: isValidFieldName(String)
null
.render(String)
String getPlainUserFieldValueAsHtml(String aPlainUserFieldValue)
Note! This method is stateless, i.e. you don't have to have a user identity loaded to call this method.
Typically you would always use the render(String)
whenever possible. This method should only be used when you have a plain
text user field value, but no user identity (e.g. in large search results where you want to avoid loading lots of user identity objects).
The rendered output of the plain text user field value is handled as:
EndecUtil.escapeXML(String)
)EndecUtil.br(String)
)OutputUtil.getHyperlinkedText(String)
)aPlainUserFieldValue
- the plain text user field valuenull
.SiteVision - Portal and Content Management Made Easy
SiteVision is an advanced Java enterprise portal product and a portlet container (JSR 286) that implements Java Content Repository (JSR 283).
Copyright© 2008-2018 SiteVision AB, all rights reserved.