Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to process string value after 'el' processing

Reply
Thread Tools

How to process string value after 'el' processing

 
 
Berlin Brown
Guest
Posts: n/a
 
      01-03-2007
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}"/>
<cut value="${concatValue.word}" />
</c:forEach>

 
Reply With Quote
 
 
 
 
Daniel Pitts
Guest
Posts: n/a
 
      01-03-2007

Berlin Brown wrote:
> 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}"/>
> <cut 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.

 
Reply With Quote
 
 
 
 
Berlin Brown
Guest
Posts: n/a
 
      01-03-2007

Daniel Pitts wrote:
> Berlin Brown wrote:
> > 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}"/>
> > <cut 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.



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?

 
Reply With Quote
 
Daniel Pitts
Guest
Posts: n/a
 
      01-03-2007

Berlin Brown wrote:
> Daniel Pitts wrote:
> > Berlin Brown wrote:
> > > 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}"/>
> > > <cut 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.

>
>
> 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.

 
Reply With Quote
 
Manish Pandit
Guest
Posts: n/a
 
      01-03-2007
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

 
Reply With Quote
 
Berlin Brown
Guest
Posts: n/a
 
      01-04-2007

Daniel Pitts wrote:
> Berlin Brown wrote:
> > Daniel Pitts wrote:
> > > Berlin Brown wrote:
> > > > 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}"/>
> > > > <cut 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.

> >
> >
> > 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.


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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Howto identify a string value vs. a numeric value in std::string frohlinger@gmail.com C++ 9 09-19-2007 09:34 AM
Re: command string good in subprocess.Popen(string) fails inprocess.Process(string) Trent Mick Python 0 05-16-2005 04:51 PM
command string good in subprocess.Popen(string) fails inprocess.Process(string) Earl Eiland Python 3 05-16-2005 04:48 PM
String.value and String.value.length doesn't works together in IE with JVM Wee Javascript 1 07-16-2003 12:32 PM



Advertisments