Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2007

Tip: Looking for answers? Try searching our database.

How to process string value after 'el' processing

Thread view: 
Berlin  Brown - 03 Jan 2007 21:24 GMT
I have a jsp jstl question.  It is actually kind of simple, but I still
couldnt get an answer.  And it is more of a design question.

How do you do 'processing' or manipulation of a string value 'after' it
has been processed through 'el' jstl?

"I am having trouble doing basic view manipulation on data output from
the expression language. I dont 'think' I need custom tags for this,
and dont think this logic should occur at the controller or model? But
for example, if I want to modify a value before it is display to the
user but after it has been evaluated: Ie."

This is my current approach.
Would it have been more logical to place:

"<jsp:useBean id="concatValue"
class="org.spirit.servlet.bean.BotListConcatValue" />
<jsp:setProperty name="concatValue" property="maxLen" value="20" />"

Within the 'forEach' bracket?

Logic in the bean:

    public String getWord() {
        if (word != null && (word.length() > (maxLen + 3))) {
            word = word.substring(0, (maxLen - 1)) + "...";
        }
        return word;
    }

<jsp:useBean id="concatValue"
class="org.spirit.servlet.bean.BotListConcatValue" />
<jsp:setProperty name="concatValue" property="maxLen" value="20" />
<c:forEach items="${linklistings}"
  var="listing" varStatus="status">
<c:set target="${concatValue}" property="word"
value="${listing.urlTitle}"/>
<c:out value="${concatValue.word}" />
</c:forEach>
Daniel Pitts - 03 Jan 2007 21:39 GMT
> I have a jsp jstl question.  It is actually kind of simple, but I still
> couldnt get an answer.  And it is more of a design question.
[quoted text clipped - 35 lines]
> <c:out value="${concatValue.word}" />
> </c:forEach>
You don't NEED a special tag for this, but I would probably implement
it that way.  Or make it a el function.  Either way, adding it the the
TLD is the right approach, instead of using the bean the way you do.

I agree, it doesn't really belong in the controller or the model, as it
is specific to the rendering (i.e., view) of the data.

Creating a TLD isn't too hard, and it is very easy to add an el
function (you can basically use a static function).

public static String trim(String word) {
   if (word != null && (word.length() > (maxLen + 3))) {
       word = word.substring(0, (maxLen - 1)) + "...";
   return word;
}

and use ${mytld:trim(listing.urlTitle)} to display it.

Hope this helps,
Daniel.
Berlin  Brown - 03 Jan 2007 22:04 GMT
> > I have a jsp jstl question.  It is actually kind of simple, but I still
> > couldnt get an answer.  And it is more of a design question.
[quoted text clipped - 55 lines]
> Hope this helps,
> Daniel.

I tried that, but I dont think the version of TLD I am using supports
'functions'.  I am using pre JSP 2.0 code and I believe jstl 1.2?
Daniel Pitts - 03 Jan 2007 22:25 GMT
> > > I have a jsp jstl question.  It is actually kind of simple, but I still
> > > couldnt get an answer.  And it is more of a design question.
[quoted text clipped - 58 lines]
> I tried that, but I dont think the version of TLD I am using supports
> 'functions'.  I am using pre JSP 2.0 code and I believe jstl 1.2?

Okay, then a tag is the way to go.
Or, *gasp* upgrading to the latest standard.
Berlin  Brown - 04 Jan 2007 20:30 GMT
> > > > I have a jsp jstl question.  It is actually kind of simple, but I still
> > > > couldnt get an answer.  And it is more of a design question.
[quoted text clipped - 61 lines]
> Okay, then a tag is the way to go.
> Or, *gasp* upgrading to the latest standard.

Yea, it was a fight; but I updated my app to most recent specs.  It was
amazing how different things are.

Berlin Brown
http://www.newspiritcompany.com/botlist/
Botlist - Ad Listings
Manish Pandit - 03 Jan 2007 23:49 GMT
You can try using the JSTL functions library to achieve this via EL.
You can use fn:length to get the length, and fn:substring to get the
subset.

-cheers,
Manish


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.