Solved

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

Posted on 2006-07-15
2
798 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Scenario: Your operations manager has discovered an anomaly in your security system. The business will start to suffer within 15 minutes if it is a major IT incident. What should she do? We have 6 recommendations for managing major incidents (https:…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

895 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now