You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Stefano Tranquillini <st...@gmail.com> on 2009/06/22 17:37:46 UTC

Display only 100 chars of a string

Hi all.
there's a possibility inside a jsp to display only the first 100 chars
or the first 10 words of a string?
if i have a long string, can i display only the first 100 chars
directly in a jsp without modification in action or something like
that?
thanks
-- 
Stefano

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Display only 100 chars of a string

Posted by Greg Lindholm <gr...@gmail.com>.
I have added an abbreviate() method to our base action class.

    /**
     * Abbreviate a string using ellipses (...).<br>
     * If text is longer then len it is truncated to len characters then the
     * last 3 characters are replaced with ellipses (...).
     *
     * @param text the string to abbreviate
     * @param len the maximum length of the returned string (must be greater
     *            then 3)
     * @return the string abbreviated with ellipses to a maximum length of
     *         <code>len</code>
     */
    public String abbreviate(String text, int len)
    {
        return org.apache.commons.lang.StringUtils.abbreviate(text, len);
    }

Then in the JSP I can use it like this <s:property
value="abbreviate(name,25)" />

Re: Display only 100 chars of a string

Posted by Stefano Tranquillini <st...@gmail.com>.
@Greg: do u put that code inside the bean? i can't do this.
@Jon thanks, but i've some problem with the " of the part: "%.100s"
the system found a end tag " at the first " that it encountred. i
tried to put \" but doesn't work.

On Mon, Jun 22, 2009 at 18:00, Jon Pearson<Jo...@sixnet.com> wrote:
> <s:property value="@java.lang.String@format("%.100s", description)" />
> should work (check
> http://www.opensymphony.com/ognl/html/LanguageGuide/staticMethods.html
> for OGNL for calling static methods)
>
>> -----Original Message-----
>> From: Stefano Tranquillini [mailto:stefano.tranquillini@gmail.com]
>> Sent: Monday, June 22, 2009 11:58 AM
>> To: Struts Users Mailing List
>> Subject: Re: Display only 100 chars of a string
>>
>> On Mon, Jun 22, 2009 at 17:46, Jon
>> Pearson<Jo...@sixnet.com> wrote:
>> > String.format("%.100s", s);
>> how can i put this thing in the jsp?
>>
>>
>> --
>> Stefano
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
Stefano

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Display only 100 chars of a string

Posted by Martin Gainty <mg...@hotmail.com>.
i couldnt get that to work either..
suggest setting the value and truncating the value to a new String variable in action class or setting the value and truncating the value to a new String variable in backing bean

Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> From: stefano.tranquillini@gmail.com
> Date: Mon, 22 Jun 2009 18:26:45 +0200
> Subject: Re: Display only 100 chars of a string
> To: user@struts.apache.org
> 
> are you sure that this thing works?
> because i don't see anything.
> I'm inside an iterator , with this thing works  <s:property
> value="%{description}" /> with yours no.
> seems that description is empty when i do <s:property
> value="@java.lang.String@format('%.100s', description)" />
> 
> On Mon, Jun 22, 2009 at 18:09, Jon Pearson<Jo...@sixnet.com> wrote:
> > Sorry, I accidentally embedded double quotes inside double quotes,
> > here's a fix:
> >
> > <s:property value="@java.lang.String@format('%.100s', description)" />
> >
> >> -----Original Message-----
> >> From: stefano.tranquillini@gmail.com
> >> [mailto:stefano.tranquillini@gmail.com] On Behalf Of Stefano
> >> Sent: Monday, June 22, 2009 12:07 PM
> >> To: Struts Users Mailing List
> >> Subject: Re: Display only 100 chars of a string
> >>
> >> @Greg: do u put that code inside the bean? i can't do this.
> >> @Jon thanks, but i've some problem with the " of the part: "%.100s"
> >> the system found a end tag " at the first " that it encountred. i
> >> tried to put \" but doesn't work.
> >>
> >> On Mon, Jun 22, 2009 at 18:00, Jon
> >> Pearson<Jo...@sixnet.com> wrote:
> >> > <s:property value="@java.lang.String@format("%.100s",
> >> description)" />
> >> > should work (check
> >> >
> >> http://www.opensymphony.com/ognl/html/LanguageGuide/staticMethods.html
> >> > for OGNL for calling static methods)
> >> >
> >> >> -----Original Message-----
> >> >> From: Stefano Tranquillini [mailto:stefano.tranquillini@gmail.com]
> >> >> Sent: Monday, June 22, 2009 11:58 AM
> >> >> To: Struts Users Mailing List
> >> >> Subject: Re: Display only 100 chars of a string
> >> >>
> >> >> On Mon, Jun 22, 2009 at 17:46, Jon
> >> >> Pearson<Jo...@sixnet.com> wrote:
> >> >> > String.format("%.100s", s);
> >> >> how can i put this thing in the jsp?
> >> >>
> >> >>
> >> >> --
> >> >> Stefano
> >> >>
> >> >>
> >> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> >> For additional commands, e-mail: user-help@struts.apache.org
> >> >>
> >> >>
> >> >
> >> >
> >> ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> > For additional commands, e-mail: user-help@struts.apache.org
> >> >
> >> >
> >>
> >>
> >>
> >> --
> >> Stefano
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> 
> 
> 
> -- 
> Stefano
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

_________________________________________________________________
Microsoft brings you a new way to search the web.  Try  Bing™ now
http://www.bing.com?form=MFEHPG&publ=WLHMTAG&crea=TEXT_MFEHPG_Core_tagline_try bing_1x1

Re: Display only 100 chars of a string

Posted by Wes Wannemacher <we...@wantii.com>.
On Mon, Jun 22, 2009 at 12:26 PM, Stefano
Tranquillini<st...@gmail.com> wrote:
> are you sure that this thing works?
> because i don't see anything.
> I'm inside an iterator , with this thing works  <s:property
> value="%{description}" /> with yours no.
> seems that description is empty when i do <s:property
> value="@java.lang.String@format('%.100s', description)" />
>

In his example, the stack is searched for a property called
'description', in the new version of the tag, you probably have to
explicitly tell OGNL where to find 'description'. Try the following -

<s:property value="@java.lang.String@format('%.100s', #top.description)" />

(I think it's #top, but I could be wrong, perhaps one of the OGNL
gurus can chime in).

-Wes
-- 
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Display only 100 chars of a string

Posted by Dave Newton <ne...@yahoo.com>.
Stefano Tranquillini wrote:
> About this link:
> http://www.opensymphony.com/ognl/html/LanguageGuide/staticMethods.html
> 
> said: You can call a static method using the syntax
> @class@method(args). If you leave out class, it defaults to
> java.lang.Math, to make it easier to call min and max methods. If you
> specify the class, you must give the fully qualified name.
> 
> but, i don't understand how to call the min method of math is i.e.
> @method(min(100,1000)) ?? or what else?

What have you tried so far? I sure wouldn't think the word "method" 
should appear--why not just try what seems obvious, for example 
"@@min(...)" or "@min(...)"?

I think I'd be more comfortable specifying the full class anyway.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Display only 100 chars of a string

Posted by Stefano Tranquillini <st...@gmail.com>.
About this link:
http://www.opensymphony.com/ognl/html/LanguageGuide/staticMethods.html

said: You can call a static method using the syntax
@class@method(args). If you leave out class, it defaults to
java.lang.Math, to make it easier to call min and max methods. If you
specify the class, you must give the fully qualified name.

but, i don't understand how to call the min method of math is i.e.
@method(min(100,1000)) ?? or what else?

thanks




-- 
Stefano

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Display only 100 chars of a string

Posted by Dave Newton <ne...@yahoo.com>.
Wes Wannemacher wrote:
> No, Jon, you are right... This belongs in the action class. Just
> because OGNL lets you cheat doesn't mean you should (cue Dave jumping
> in any minute).

Hey!

I'm of two minds regarding this... Truncating a string is really a 
view-layer issue, handled (or instigated) by a designer (which is 
usually us) or a design-driven process.

That said, if it's a site-wide thing--where does it belong? Maybe a 
custom tag, which is kind of a compromise: the OGNL treachery is 
localized (if done in OGNL), or the scriptlet, or a utility call into 
the app, etc.

If I was doing it myself I'd probably just "cheat", or create a 
JSP-based custom tag that wrapped it up and hid it away.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Display only 100 chars of a string

Posted by Wes Wannemacher <we...@wantii.com>.
On Mon, Jun 22, 2009 at 12:32 PM, Jon Pearson<Jo...@sixnet.com> wrote:
> I could be wrong...
>
> Honestly, you'd be better off adding a function to your action class
> that would format a string to a specific length. It would be clearer
> what was going on. Something like
>
> public String formatString(String s, int maxLen) {
>  return String.format("%." + maxLen + "s", s);
> }
>
> It would also be an easy extension later if you decided that you wanted
> truncated strings to end with elipses:
>
> public String formatString(String s, int maxLen) {
>  if (s.length() < maxLen) {
>    return s;
>  } else {
>    return s.substring(0, maxLen - 3) + "...";
>  }
> }
>
>

No, Jon, you are right... This belongs in the action class. Just
because OGNL lets you cheat doesn't mean you should (cue Dave jumping
in any minute). I think the OP mentioned at one point that adding this
to the action is not an option.

Also, another choice is to use JavaScript. Is the choice to abbreviate
because of bandwidth or screen real estate?

-Wes

-- 
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Display only 100 chars of a string

Posted by Jon Pearson <Jo...@sixnet.com>.
I could be wrong...

Honestly, you'd be better off adding a function to your action class
that would format a string to a specific length. It would be clearer
what was going on. Something like

public String formatString(String s, int maxLen) {
  return String.format("%." + maxLen + "s", s);
}

It would also be an easy extension later if you decided that you wanted
truncated strings to end with elipses:

public String formatString(String s, int maxLen) {
  if (s.length() < maxLen) {
    return s;
  } else {
    return s.substring(0, maxLen - 3) + "...";
  }
}


> -----Original Message-----
> From: Stefano Tranquillini [mailto:stefano.tranquillini@gmail.com] 
> Sent: Monday, June 22, 2009 12:27 PM
> To: Struts Users Mailing List
> Subject: Re: Display only 100 chars of a string
> 
> are you sure that this thing works?
> because i don't see anything.
> I'm inside an iterator , with this thing works  <s:property
> value="%{description}" /> with yours no.
> seems that description is empty when i do <s:property
> value="@java.lang.String@format('%.100s', description)" />
> 
> On Mon, Jun 22, 2009 at 18:09, Jon 
> Pearson<Jo...@sixnet.com> wrote:
> > Sorry, I accidentally embedded double quotes inside double quotes,
> > here's a fix:
> >
> > <s:property value="@java.lang.String@format('%.100s', 
> description)" />
> >
> >> -----Original Message-----
> >> From: stefano.tranquillini@gmail.com
> >> [mailto:stefano.tranquillini@gmail.com] On Behalf Of Stefano
> >> Sent: Monday, June 22, 2009 12:07 PM
> >> To: Struts Users Mailing List
> >> Subject: Re: Display only 100 chars of a string
> >>
> >> @Greg: do u put that code inside the bean? i can't do this.
> >> @Jon thanks, but i've some problem with the " of the part: "%.100s"
> >> the system found a end tag " at the first " that it encountred. i
> >> tried to put \" but doesn't work.
> >>
> >> On Mon, Jun 22, 2009 at 18:00, Jon
> >> Pearson<Jo...@sixnet.com> wrote:
> >> > <s:property value="@java.lang.String@format("%.100s",
> >> description)" />
> >> > should work (check
> >> >
> >> 
> http://www.opensymphony.com/ognl/html/LanguageGuide/staticMethods.html
> >> > for OGNL for calling static methods)
> >> >
> >> >> -----Original Message-----
> >> >> From: Stefano Tranquillini 
> [mailto:stefano.tranquillini@gmail.com]
> >> >> Sent: Monday, June 22, 2009 11:58 AM
> >> >> To: Struts Users Mailing List
> >> >> Subject: Re: Display only 100 chars of a string
> >> >>
> >> >> On Mon, Jun 22, 2009 at 17:46, Jon
> >> >> Pearson<Jo...@sixnet.com> wrote:
> >> >> > String.format("%.100s", s);
> >> >> how can i put this thing in the jsp?
> >> >>
> >> >>
> >> >> --
> >> >> Stefano
> >> >>
> >> >>
> >> 
> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> >> For additional commands, e-mail: user-help@struts.apache.org
> >> >>
> >> >>
> >> >
> >> >
> >> 
> ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> > For additional commands, e-mail: user-help@struts.apache.org
> >> >
> >> >
> >>
> >>
> >>
> >> --
> >> Stefano
> >>
> >> 
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> 
> 
> 
> -- 
> Stefano
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Display only 100 chars of a string

Posted by Stefano Tranquillini <st...@gmail.com>.
are you sure that this thing works?
because i don't see anything.
I'm inside an iterator , with this thing works  <s:property
value="%{description}" /> with yours no.
seems that description is empty when i do <s:property
value="@java.lang.String@format('%.100s', description)" />

On Mon, Jun 22, 2009 at 18:09, Jon Pearson<Jo...@sixnet.com> wrote:
> Sorry, I accidentally embedded double quotes inside double quotes,
> here's a fix:
>
> <s:property value="@java.lang.String@format('%.100s', description)" />
>
>> -----Original Message-----
>> From: stefano.tranquillini@gmail.com
>> [mailto:stefano.tranquillini@gmail.com] On Behalf Of Stefano
>> Sent: Monday, June 22, 2009 12:07 PM
>> To: Struts Users Mailing List
>> Subject: Re: Display only 100 chars of a string
>>
>> @Greg: do u put that code inside the bean? i can't do this.
>> @Jon thanks, but i've some problem with the " of the part: "%.100s"
>> the system found a end tag " at the first " that it encountred. i
>> tried to put \" but doesn't work.
>>
>> On Mon, Jun 22, 2009 at 18:00, Jon
>> Pearson<Jo...@sixnet.com> wrote:
>> > <s:property value="@java.lang.String@format("%.100s",
>> description)" />
>> > should work (check
>> >
>> http://www.opensymphony.com/ognl/html/LanguageGuide/staticMethods.html
>> > for OGNL for calling static methods)
>> >
>> >> -----Original Message-----
>> >> From: Stefano Tranquillini [mailto:stefano.tranquillini@gmail.com]
>> >> Sent: Monday, June 22, 2009 11:58 AM
>> >> To: Struts Users Mailing List
>> >> Subject: Re: Display only 100 chars of a string
>> >>
>> >> On Mon, Jun 22, 2009 at 17:46, Jon
>> >> Pearson<Jo...@sixnet.com> wrote:
>> >> > String.format("%.100s", s);
>> >> how can i put this thing in the jsp?
>> >>
>> >>
>> >> --
>> >> Stefano
>> >>
>> >>
>> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> >> For additional commands, e-mail: user-help@struts.apache.org
>> >>
>> >>
>> >
>> >
>> ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> > For additional commands, e-mail: user-help@struts.apache.org
>> >
>> >
>>
>>
>>
>> --
>> Stefano
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
Stefano

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Display only 100 chars of a string

Posted by Jon Pearson <Jo...@sixnet.com>.
Sorry, I accidentally embedded double quotes inside double quotes,
here's a fix:

<s:property value="@java.lang.String@format('%.100s', description)" />

> -----Original Message-----
> From: stefano.tranquillini@gmail.com 
> [mailto:stefano.tranquillini@gmail.com] On Behalf Of Stefano
> Sent: Monday, June 22, 2009 12:07 PM
> To: Struts Users Mailing List
> Subject: Re: Display only 100 chars of a string
> 
> @Greg: do u put that code inside the bean? i can't do this.
> @Jon thanks, but i've some problem with the " of the part: "%.100s"
> the system found a end tag " at the first " that it encountred. i
> tried to put \" but doesn't work.
> 
> On Mon, Jun 22, 2009 at 18:00, Jon 
> Pearson<Jo...@sixnet.com> wrote:
> > <s:property value="@java.lang.String@format("%.100s", 
> description)" />
> > should work (check
> > 
> http://www.opensymphony.com/ognl/html/LanguageGuide/staticMethods.html
> > for OGNL for calling static methods)
> >
> >> -----Original Message-----
> >> From: Stefano Tranquillini [mailto:stefano.tranquillini@gmail.com]
> >> Sent: Monday, June 22, 2009 11:58 AM
> >> To: Struts Users Mailing List
> >> Subject: Re: Display only 100 chars of a string
> >>
> >> On Mon, Jun 22, 2009 at 17:46, Jon
> >> Pearson<Jo...@sixnet.com> wrote:
> >> > String.format("%.100s", s);
> >> how can i put this thing in the jsp?
> >>
> >>
> >> --
> >> Stefano
> >>
> >> 
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> 
> 
> 
> -- 
> Stefano
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Display only 100 chars of a string

Posted by Greg Lindholm <gr...@gmail.com>.
On Mon, Jun 22, 2009 at 12:07 PM, Stefano <el...@gmail.com> wrote:

> @Greg: do u put that code inside the bean? i can't do this.
>

I put the abbreviate() method in the action class. It's actually in our
'base' action class so it's always available.

Re: Display only 100 chars of a string

Posted by Stefano <el...@gmail.com>.
@Greg: do u put that code inside the bean? i can't do this.
@Jon thanks, but i've some problem with the " of the part: "%.100s"
the system found a end tag " at the first " that it encountred. i
tried to put \" but doesn't work.

On Mon, Jun 22, 2009 at 18:00, Jon Pearson<Jo...@sixnet.com> wrote:
> <s:property value="@java.lang.String@format("%.100s", description)" />
> should work (check
> http://www.opensymphony.com/ognl/html/LanguageGuide/staticMethods.html
> for OGNL for calling static methods)
>
>> -----Original Message-----
>> From: Stefano Tranquillini [mailto:stefano.tranquillini@gmail.com]
>> Sent: Monday, June 22, 2009 11:58 AM
>> To: Struts Users Mailing List
>> Subject: Re: Display only 100 chars of a string
>>
>> On Mon, Jun 22, 2009 at 17:46, Jon
>> Pearson<Jo...@sixnet.com> wrote:
>> > String.format("%.100s", s);
>> how can i put this thing in the jsp?
>>
>>
>> --
>> Stefano
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
Stefano

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Display only 100 chars of a string

Posted by Jon Pearson <Jo...@sixnet.com>.
<s:property value="@java.lang.String@format("%.100s", description)" />
should work (check
http://www.opensymphony.com/ognl/html/LanguageGuide/staticMethods.html
for OGNL for calling static methods) 

> -----Original Message-----
> From: Stefano Tranquillini [mailto:stefano.tranquillini@gmail.com] 
> Sent: Monday, June 22, 2009 11:58 AM
> To: Struts Users Mailing List
> Subject: Re: Display only 100 chars of a string
> 
> On Mon, Jun 22, 2009 at 17:46, Jon 
> Pearson<Jo...@sixnet.com> wrote:
> > String.format("%.100s", s);
> how can i put this thing in the jsp?
> 
> 
> -- 
> Stefano
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Display only 100 chars of a string

Posted by Stefano Tranquillini <st...@gmail.com>.
On Mon, Jun 22, 2009 at 17:46, Jon Pearson<Jo...@sixnet.com> wrote:
> String.format("%.100s", s);
how can i put this thing in the jsp?


-- 
Stefano

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Display only 100 chars of a string

Posted by Jon Pearson <Jo...@sixnet.com>.
That would cause an IndexOutOfBoundsException if the string was shorter
than 100 chars. Try this instead:

String.format("%.100s", s);

That would return up to 100 characters from the beginning of the string
's'.
 

> -----Original Message-----
> From: Avlesh Singh [mailto:avlesh@gmail.com] 
> Sent: Monday, June 22, 2009 11:42 AM
> To: Struts Users Mailing List
> Subject: Re: Display only 100 chars of a string
> 
> <c:out value="${fn:substring(yourString, start, end)}"/>
> 
> Cheers
> Avlesh
> 
> On Mon, Jun 22, 2009 at 9:07 PM, Stefano Tranquillini <
> stefano.tranquillini@gmail.com> wrote:
> 
> > Hi all.
> > there's a possibility inside a jsp to display only the 
> first 100 chars
> > or the first 10 words of a string?
> > if i have a long string, can i display only the first 100 chars
> > directly in a jsp without modification in action or something like
> > that?
> > thanks
> > --
> > Stefano
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Display only 100 chars of a string

Posted by Avlesh Singh <av...@gmail.com>.
<c:out value="${fn:substring(yourString, start, end)}"/>

Cheers
Avlesh

On Mon, Jun 22, 2009 at 9:07 PM, Stefano Tranquillini <
stefano.tranquillini@gmail.com> wrote:

> Hi all.
> there's a possibility inside a jsp to display only the first 100 chars
> or the first 10 words of a string?
> if i have a long string, can i display only the first 100 chars
> directly in a jsp without modification in action or something like
> that?
> thanks
> --
> Stefano
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Display only 100 chars of a string

Posted by Stefano Tranquillini <st...@gmail.com>.
i found a solution: <s:property value="%{description.substring(0,200)}" />

On Mon, Jun 22, 2009 at 17:40, Jim Kiley <jh...@summa-tech.com> wrote:

> This seems like the kind of thing that is crying out for a custom tag --
> and
> I don't say that lightly.  I mean, a scriptlet could do it, but scriptlets
> are from the devil.  A custom tag would be a better solution, especially
> since this is a pretty general problem.
> jk
>
> On Mon, Jun 22, 2009 at 11:37 AM, Stefano Tranquillini <
> stefano.tranquillini@gmail.com> wrote:
>
> > Hi all.
> > there's a possibility inside a jsp to display only the first 100 chars
> > or the first 10 words of a string?
> > if i have a long string, can i display only the first 100 chars
> > directly in a jsp without modification in action or something like
> > that?
> > thanks
> > --
> > Stefano
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> --
> Jim Kiley
> Senior Technical Consultant | Summa
> [p] 412.258.3346
> http://www.summa-tech.com
>



-- 
Stefano

Re: Display only 100 chars of a string

Posted by Jim Kiley <jh...@summa-tech.com>.
This seems like the kind of thing that is crying out for a custom tag -- and
I don't say that lightly.  I mean, a scriptlet could do it, but scriptlets
are from the devil.  A custom tag would be a better solution, especially
since this is a pretty general problem.
jk

On Mon, Jun 22, 2009 at 11:37 AM, Stefano Tranquillini <
stefano.tranquillini@gmail.com> wrote:

> Hi all.
> there's a possibility inside a jsp to display only the first 100 chars
> or the first 10 words of a string?
> if i have a long string, can i display only the first 100 chars
> directly in a jsp without modification in action or something like
> that?
> thanks
> --
> Stefano
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Jim Kiley
Senior Technical Consultant | Summa
[p] 412.258.3346
http://www.summa-tech.com