I have been using JSF + RF for over 2 years and have’nt had a chance to extend the existing capabilities of components.
Now the requirement is I have to trim the string and display it if it is more than 25 characters.
This has been achieved as below
<c:choose>
<c:when test="#{fn:length(teststep.name) > 25}">
<h:outputText title="#{teststep.name}" value="#{fn:substring(teststep.name, 0, 25)}..."/>
</c:when>
<c:otherwise>
<h:outputText title="#{teststep.name}" value="#{teststep.name}"/>
</c:otherwise>
</c:choose>
But I use this code in lot many places (and want to avoid boilerplate code of 8 lines everytime) so thought of custom h:outputText to provide trim functionality.
Could you let me know how would I write a custom tag in JSF
Regards,
Satya
Assuming that you’re using JSP not Facelets, put the content in a
.tagfile in/WEB-INF, like/WEB-INF/tags/outputLimitedText.tag.Then you can reference it as follows:
You could also use a
Converter.with
You could also create a custom EL function. So that you end up with
A concrete example of the EL function is given in this answer: How to concatenate Strings in EL?