Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-07-15
2
Medium Priority
?
805 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 1500 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

In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Today as you open your Outlook, you witness an error message: “Outlook is using an old copy of your Outlook Data File…”. Probably, Outlook is accessing an old OST file.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

877 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