Solved

how do I truncate variable output data from the page side?

Posted on 2006-07-15
2
802 Views
Last Modified: 2012-08-14
I want to truncate the amount of data displayed from the output of a variable using a control on the jsp page.
For example, if the following statement is a string with a value of up to 512 characters:
If <c:out value="${bigField.content}" /> = Now is the time for all good men to come to the aid of their country.
I would like to use some JSP page side control to limit the output to say 20 characters and an ellipsis (...)
so the result would be something similar to:
<fmt:format??? valuevalue="${bigField.content}" display="20" /> = Now is the time for ...
I don't want to do this from the server side because I want the "page designer" to be able to control the amount of data that is displayed.
 

0
Comment
Question by:Belshe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Expert Comment

by:bloodredsun
ID: 17115984
Are you using JSTL 1.0 or 1.1?

If you are using 1.1 then you can use the fn/function library to substring the variable if it has a length of greater than 512 characters.
0
 
LVL 9

Accepted Solution

by:
owenli27 earned 500 total points
ID: 17121918
If you only want to do this in client side, you may use Javascript to control it. try this:

<body>
<script language="javascript">

var str = <c:out value="${bigField.content}" />
if(str.length > 512){
    str = str.substring(0, 20) + "...";

    document.write("<FONT COLOR=\"RED\">");
    document.write(str);
}      
</script>
</body>
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How many times a day do you open, acknowledge, or close an IT incident? What’s your process? Do you have a process depending on the incident, systems involved, and other factors? New Relic Alerts gives you options for how you interact with notifica…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question