[OmniFaces utilities] The
abbreviate()
function abbreviate the given text on the given size limit with ellipsis.Function:
Usage:
Using the of:abbreviate() function is pretty straightforward. Basically, we need to provide a string and size of the substring to be displayed. Below, you can see an example using <c:set>:
<c:set
var="description" value="This is a very long text with a very
long description" />
<h:outputText
value="#{of:abbreviate(description,
24)}"/>
Or, the
string can come from a managed bean:
public class MyBean {
private String longDescription = "This is
a very long text with a very long description";
public String
getLongDescription() {
return longDescription;
}
...
}
<h:outputText value="#{of:abbreviate(myBean.longDescription,
24)}"/>
Both
examples will output:
This is a very long text...
For example,
this function is useful for creating tooltips. Below you can see it at work via
PrimeFaces tooltip
component:
<h:outputLink id="descriptionId"
value="#">
<h:outputText
value="#{of:abbreviate(myBean.longDescription, 24)}" />
</h:outputLink>
<p:tooltip id="toolTipDescriptionId"
for="descriptionId" value="#{myBean.longDescription}" />
When we
hover the abbreviated text, we will see the entire text as a tooltip:
The of:abbreviate() can be used in tables to abbreviate long
texts in cells, in collapsible divs/panels, in callouts, banners, etc.
Niciun comentariu :
Trimiteți un comentariu