You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adam Hardy <ah...@cyberspaceroad.com> on 2007/11/04 17:06:42 UTC
EL expressions and string concatenation
This is slightly off-topic but I hope not too much, and there is a reference to
struts here because I used to do this with struts1 taglibs!
I want to concatenate 2 vars into a string in EL but since one is a Long, EL
can't do it, and throws a NumberFormatException because it wants them both to be
Longs so it can do arithmetic addition instead.
<a href="${pc:url('/category/edit.html?category.id=' + category.id)}"
title="" class="icon">
<img src="${pc:url('/images/doc1.png')}" alt=""/>
</a>
pc:url is my taglib function that accepts a string parameter.
I see 3 possible solutions:
- put in a JSTL <url>
- create a new taglib function that takes parameters for URL parameters
- create a new taglib function that concatenates all types into strings
or is there a neat work-around I haven't thought of?
Lastly, is there anyone else taking this minimalist approach who would like to
open-source this stuff with me?
Thanks
Adam
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] EL expressions and string concatenation
Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Antonio Petrelli on 05/11/07 08:14, wrote:
> 2007/11/4, Adam Hardy <ah...@cyberspaceroad.com>:
>> Antonio Petrelli on 04/11/07 16:17, wrote:
>>> 2007/11/4, Adam Hardy <ah...@cyberspaceroad.com>:
>>>> I want to concatenate 2 vars into a string in EL but since one is a
>> Long, EL
>>>> can't do it, and throws a NumberFormatException because it wants them
>> both to be
>>>> Longs so it can do arithmetic addition instead.
>>> You could set a string variable this way:
>>> <c:set var="myStringVariable"><c:out value="${category.id}"/></c:set>
>> That's not quite the minimalist approach I was thinking of, but it is one
>> approach.
>
>
>
> Anyway I wonder what does it prevent you from using <c:url> and <c:param>...
To keep the JSP short and clear. Instead of these tags:
<c:url value="edit.html" var="url1">
<c:param name="category.id">${category.id}</c:param>
</c:url>
<a href="${url1}">xxxxx......</a>
do it with JSTL-EL:
<a href="${pc:url(pc:concat('edit.html?category.id=', category.id))}">
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] EL expressions and string concatenation
Posted by Antonio Petrelli <an...@gmail.com>.
2007/11/4, Adam Hardy <ah...@cyberspaceroad.com>:
>
> Antonio Petrelli on 04/11/07 16:17, wrote:
> > 2007/11/4, Adam Hardy <ah...@cyberspaceroad.com>:
> >> I want to concatenate 2 vars into a string in EL but since one is a
> Long, EL
> >> can't do it, and throws a NumberFormatException because it wants them
> both to be
> >> Longs so it can do arithmetic addition instead.
> >
> > You could set a string variable this way:
> > <c:set var="myStringVariable"><c:out value="${category.id}"/></c:set>
>
> That's not quite the minimalist approach I was thinking of, but it is one
> approach.
Anyway I wonder what does it prevent you from using <c:url> and <c:param>...
Antonio
Re: [OT] EL expressions and string concatenation
Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Antonio Petrelli on 04/11/07 16:17, wrote:
> 2007/11/4, Adam Hardy <ah...@cyberspaceroad.com>:
>> I want to concatenate 2 vars into a string in EL but since one is a Long, EL
>> can't do it, and throws a NumberFormatException because it wants them both to be
>> Longs so it can do arithmetic addition instead.
>
> You could set a string variable this way:
> <c:set var="myStringVariable"><c:out value="${category.id}"/></c:set>
That's not quite the minimalist approach I was thinking of, but it is one approach.
Another approach which saves that whole line is to write another taglib function
and use it like this:
<a href="${pc:url(pc:concat('/category/edit.html?id=', category.id))}">
where pc: is my taglibrary, but I'd like to avoid a proliferation of these
taglib functions in my app.
regards
Adam
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
[OT] Re: EL expressions and string concatenation
Posted by Antonio Petrelli <an...@gmail.com>.
2007/11/4, Adam Hardy <ah...@cyberspaceroad.com>:
> I want to concatenate 2 vars into a string in EL but since one is a Long, EL
> can't do it, and throws a NumberFormatException because it wants them both to be
> Longs so it can do arithmetic addition instead.
You could set a string variable this way:
<c:set var="myStringVariable"><c:out value="${category.id}"/></c:set>
Antonio
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: EL expressions and string concatenation
Posted by "Karr, David" <da...@wamu.net>.
Would this work?
href="${pc:url('/category/edit.html?category.id=')}${category.id}"
> -----Original Message-----
> From: Adam Hardy [mailto:ahardy.struts@cyberspaceroad.com]
> Sent: Sunday, November 04, 2007 8:07 AM
> To: Struts Users Mailing List
> Subject: EL expressions and string concatenation
>
> This is slightly off-topic but I hope not too much, and there
> is a reference to struts here because I used to do this with
> struts1 taglibs!
>
> I want to concatenate 2 vars into a string in EL but since
> one is a Long, EL can't do it, and throws a
> NumberFormatException because it wants them both to be Longs
> so it can do arithmetic addition instead.
>
> <a href="${pc:url('/category/edit.html?category.id=' + category.id)}"
> title="" class="icon">
> <img src="${pc:url('/images/doc1.png')}" alt=""/> </a>
>
> pc:url is my taglib function that accepts a string parameter.
>
> I see 3 possible solutions:
> - put in a JSTL <url>
> - create a new taglib function that takes parameters for
> URL parameters
> - create a new taglib function that concatenates all types
> into strings
>
> or is there a neat work-around I haven't thought of?
>
> Lastly, is there anyone else taking this minimalist approach
> who would like to open-source this stuff with me?
>
> Thanks
> Adam
>
> ---------------------------------------------------------------------
> 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