Solved

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

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
With the rising number of cyber attacks in recent years, keeping your personal data safe has become more important than ever. The tips outlined in this article will help you keep your identitfy safe.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

624 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