Solved

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

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

A procedure for exporting installed hotfix details of remote computers using powershell
We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

19 Experts available now in Live!

Get 1:1 Help Now