Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7529919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:46:09+00:00 2026-05-30T04:46:09+00:00

I have been using JSF + RF for over 2 years and have’nt had

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:46:10+00:00Added an answer on May 30, 2026 at 4:46 am

    Assuming that you’re using JSP not Facelets, put the content in a .tag file in /WEB-INF, like /WEB-INF/tags/outputLimitedText.tag.

    <%@ tag body-content="empty" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
    <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
    <c:choose>
        <c:when test="#{fn:length(value) > maxlength}">
            <h:outputText title="#{value}" value="#{fn:substring(value, 0, maxlength)}..."/>
        </c:when>
        <c:otherwise>
            <h:outputText title="#{value}" value="#{value}"/>
        </c:otherwise>
    </c:choose>
    

    Then you can reference it as follows:

    <%@ taglib prefix="my" tagdir="/WEB-INF/tags" %> 
    ...
    <my:outputLimitedText value="#{teststep.name}" maxlength="25" />
    

    You could also use a Converter.

    <h:outputText title="#{teststep.name}" value="#{teststep.name}">
        <f:converter converterId="substringConverter" />
        <f:attribute name="maxlength" value="25" />
    </h:outputText>
    

    with

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        String string = (String) value;
        int maxlength = Integer.valueOf((String) component.getAttributes().get("maxlength"));
    
        if (string.length() > maxlength) {
            return string.substring(0, maxlength) + "...";
        } else {
            return string;
        }
    }
    

    You could also create a custom EL function. So that you end up with

    <h:outputText title="#{teststep.name}" value="#{util:ellipsis(teststep.name, 25)}">
    

    A concrete example of the EL function is given in this answer: How to concatenate Strings in EL?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using the CSLA framework for couple of years now for windows
I have been using a Phase Listener to debug my JSF application. Now I'm
I have been using Castle MonoRail for the last two years, but in a
I have been using C# for a while now, and going back to C++
I have been using ASP.NET for years, but I can never remember when using
I have been using Ruby for a while now and I find, for bigger
I have been using IoC for a little while now and I am curious
I have been investigating a JSF upgrade on our existing web apps that are
I have been using expressions like this in JSF 1.2: rendered=#{foo.bar!=null && !foo.isBar} .
I have been building a JSF application using JPA to access the DB. There

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.