Reputation: 1378
I am using following tag for showing comments on jsp, now I want to show only first 10 character of comments...
Example: "This is very urgent please provide details"
Then <bean:write>
should write only "This is ver......"
is there any way to achieve it,
<bean:write name="order" property="ordercomments" />
Upvotes: 1
Views: 2625
Reputation: 160261
Not using the <bean:write>
tag (which in general, you shouldn't be using anyway--when JSTL functionality overlaps with Struts 1 tags, use the JSTL tag).
This kind of functionality is usually wrapped up in a custom tag, though, to allow variable lengths, add the ellipses (…) character only when necessary, break on a word boundry (don't want to say "I like your tit…" when the phrase is "I like your title suggestion"), etc.
This could be wrapped up easily in a JSP-based tag using the built-in JSP EL functionality as JB mentions, or is pretty quick to implement using a variety of other means.
Upvotes: 3
Reputation: 692023
You could easily do that using the JSTL fn:substring function, combined with the c:out
tag to make sure propert HTML escaping is done :
<c:out value="${fn:substring(someBean.someProperty, 0, 10)}" />
See http://download.oracle.com/javaee/1.4/tutorial/doc/JSTL3.html for a tutorial.
Upvotes: 3