You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Er...@swissinfo.ch on 2002/09/11 15:03:47 UTC

Dynamic string replacement?

Hi all

It looks like I found something to implement in the String Tag Library  :-)

What I'm trying to do is to create links within a text, i.e. replacing 'the
text' with '<a href="...">the text</a>'. The problem is that both the text
and the link are dynamic.
However, the String Tag Library won't let me replace things dynamically.

Consider this:

<c:set var="a" value="This will be replaced"/>
<c:set var="b" value="The new text"/>
<c:out value="${a}"/><br>
<c:out value="${b}"/><br>
<str:replace replace="This will be replaced" with="The new text">And he
said: "This will be replaced!".</str:replace>

will show

This will be replaced
The new text
And he said: "The new text!".

 - works like a charm! However,

<c:set var="a" value="This will be replaced"/>
<c:set var="b" value="The new text"/>
<c:out value="${a}"/><br>
<c:out value="${b}"/><br>
<str:replace replace="${a}" with="${b}">And he said: "This will be
replaced!".</str:replace>

won't replace anything:

This will be replaced
The new text
And he said: "This will be replaced!".


And

<c:set var="a" value="This will be replaced"/>
<c:set var="b" value="The new text"/>
<c:out value="${a}"/><br>
<c:out value="${b}"/><br>
<str:replace replace="<c:out value="${a}"/>" with="<c:out
value="${b}"/>">And he said: "This will be replaced!".</str:replace>

even gives me an exception:

javax.servlet.ServletException: /jsp/test.jsp(206,40) Attribute ${a} has no
value


This would be very, very handy if it worked... actually for all of the
String tag library.

Thanks & regards,
Eric


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Dynamic string replacement?

Posted by Glenn Nielsen <gl...@mail.more.net>.
If you need the ability to do this now, try out the regexp taglib
here at jakarta.  It implements perl style regular expressions.

Regards,

Glenn

Eric.Lewis@swissinfo.ch wrote:
> Hi all
> 
> It looks like I found something to implement in the String Tag Library  :-)
> 
> What I'm trying to do is to create links within a text, i.e. replacing 'the
> text' with '<a href="...">the text</a>'. The problem is that both the text
> and the link are dynamic.
> However, the String Tag Library won't let me replace things dynamically.
> 
> Consider this:
> 
> <c:set var="a" value="This will be replaced"/>
> <c:set var="b" value="The new text"/>
> <c:out value="${a}"/><br>
> <c:out value="${b}"/><br>
> <str:replace replace="This will be replaced" with="The new text">And he
> said: "This will be replaced!".</str:replace>
> 
> will show
> 
> This will be replaced
> The new text
> And he said: "The new text!".
> 
>  - works like a charm! However,
> 
> <c:set var="a" value="This will be replaced"/>
> <c:set var="b" value="The new text"/>
> <c:out value="${a}"/><br>
> <c:out value="${b}"/><br>
> <str:replace replace="${a}" with="${b}">And he said: "This will be
> replaced!".</str:replace>
> 
> won't replace anything:
> 
> This will be replaced
> The new text
> And he said: "This will be replaced!".
> 
> 
> And
> 
> <c:set var="a" value="This will be replaced"/>
> <c:set var="b" value="The new text"/>
> <c:out value="${a}"/><br>
> <c:out value="${b}"/><br>
> <str:replace replace="<c:out value="${a}"/>" with="<c:out
> value="${b}"/>">And he said: "This will be replaced!".</str:replace>
> 
> even gives me an exception:
> 
> javax.servlet.ServletException: /jsp/test.jsp(206,40) Attribute ${a} has no
> value
> 
> 
> This would be very, very handy if it worked... actually for all of the
> String tag library.
> 
> Thanks & regards,
> Eric
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Dynamic string replacement?

Posted by Henri Yandell <ba...@generationjava.com>.
Yep. Basically this is what we talk about when we discuss JSTLizing the
String library. I would hook up the JEL thingy to the input.

To be honest, I think it would simply involve:

1) Find the code needed in JSTL to implement this
2) Change StringTagSupport. Then all String tags are JEL'd.
3) Figure out which jar is needed to get the JEL code.

JSP 2.0 will invalidate the need for this, but I suspect it's a ways off.
So I'm happy for the String taglib to go ahead and have this and will
implement it if a patch doesn't appear at some point :)

My focus at the moment is to rearrange the tags themselves and commit the
changes all at once [after a notice of upcoming changes to the Users
list] so I don't irritate everyone with a changing library.

Any suggestions here are welcomed :) Possibly I should release a
stable-prior-to-changes-something.jar before breaking things. Will see if
that has approval on the dev list.

Hen

On Wed, 11 Sep 2002 Eric.Lewis@swissinfo.ch wrote:

> Hi all
>
> It looks like I found something to implement in the String Tag Library  :-)
>
> What I'm trying to do is to create links within a text, i.e. replacing 'the
> text' with '<a href="...">the text</a>'. The problem is that both the text
> and the link are dynamic.
> However, the String Tag Library won't let me replace things dynamically.
>
> Consider this:
>
> <c:set var="a" value="This will be replaced"/>
> <c:set var="b" value="The new text"/>
> <c:out value="${a}"/><br>
> <c:out value="${b}"/><br>
> <str:replace replace="This will be replaced" with="The new text">And he
> said: "This will be replaced!".</str:replace>
>
> will show
>
> This will be replaced
> The new text
> And he said: "The new text!".
>
>  - works like a charm! However,
>
> <c:set var="a" value="This will be replaced"/>
> <c:set var="b" value="The new text"/>
> <c:out value="${a}"/><br>
> <c:out value="${b}"/><br>
> <str:replace replace="${a}" with="${b}">And he said: "This will be
> replaced!".</str:replace>
>
> won't replace anything:
>
> This will be replaced
> The new text
> And he said: "This will be replaced!".
>
>
> And
>
> <c:set var="a" value="This will be replaced"/>
> <c:set var="b" value="The new text"/>
> <c:out value="${a}"/><br>
> <c:out value="${b}"/><br>
> <str:replace replace="<c:out value="${a}"/>" with="<c:out
> value="${b}"/>">And he said: "This will be replaced!".</str:replace>
>
> even gives me an exception:
>
> javax.servlet.ServletException: /jsp/test.jsp(206,40) Attribute ${a} has no
> value
>
>
> This would be very, very handy if it worked... actually for all of the
> String tag library.
>
> Thanks & regards,
> Eric
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Dynamic string replacement?

Posted by Vernon Wu <ve...@gatewaytech.com>.
If I understand your question right, what you want to do is the followings:

The link and text of 
<a href="...">the text</a>
need to be dynamically constructed.

The data, I assume, comes from either DB directly or the business layer of your system. Having a bean such as

class whatever {
private String text, link;
 // ...
}

construct an instance of the bean before reach the page and retrieve the value by using JSTL tags.
 

9/11/2002 10:13:15 AM, Henri Yandell <ba...@generationjava.com> wrote:

>
>Care to give an example?
>
>Are you suggesting a bean called:
>
>ReplacerBean
>
>with properties
>
>replacerBean.with
>replacerBean.replace
>replacerBean.text
>
>or some such?
>
>Seems unintuitive.
>
>
>On Wed, 11 Sep 2002, Vernon Wu wrote:
>
>>
>> That can be done by using a Java bean conjoining with JSTL.
>>
>> 9/11/2002 6:03:47 AM, Eric.Lewis@swissinfo.ch wrote:
>>
>> >Hi all
>> >
>> >It looks like I found something to implement in the String Tag Library  :-)
>> >
>> >What I'm trying to do is to create links within a text, i.e. replacing 'the
>> >text' with '<a href="...">the text</a>'. The problem is that both the text
>> >and the link are dynamic.
>> >However, the String Tag Library won't let me replace things dynamically.
>> >
>> >Consider this:
>> >
>> ><c:set var="a" value="This will be replaced"/>
>> ><c:set var="b" value="The new text"/>
>> ><c:out value="${a}"/><br>
>> ><c:out value="${b}"/><br>
>> ><str:replace replace="This will be replaced" with="The new text">And he
>> >said: "This will be replaced!".</str:replace>
>> >
>> >will show
>> >
>> >This will be replaced
>> >The new text
>> >And he said: "The new text!".
>> >
>> > - works like a charm! However,
>> >
>> ><c:set var="a" value="This will be replaced"/>
>> ><c:set var="b" value="The new text"/>
>> ><c:out value="${a}"/><br>
>> ><c:out value="${b}"/><br>
>> ><str:replace replace="${a}" with="${b}">And he said: "This will be
>> >replaced!".</str:replace>
>> >
>> >won't replace anything:
>> >
>> >This will be replaced
>> >The new text
>> >And he said: "This will be replaced!".
>> >
>> >
>> >And
>> >
>> ><c:set var="a" value="This will be replaced"/>
>> ><c:set var="b" value="The new text"/>
>> ><c:out value="${a}"/><br>
>> ><c:out value="${b}"/><br>
>> ><str:replace replace="<c:out value="${a}"/>" with="<c:out
>> >value="${b}"/>">And he said: "This will be replaced!".</str:replace>
>> >
>> >even gives me an exception:
>> >
>> >javax.servlet.ServletException: /jsp/test.jsp(206,40) Attribute ${a} has no
>> >value
>> >
>> >
>> >This would be very, very handy if it worked... actually for all of the
>> >String tag library.
>> >
>> >Thanks & regards,
>> >Eric
>> >
>> >
>> >--
>> >To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>> >For additional commands, e-mail: <ma...@jakarta.apache.org>
>> >
>> >
>>
>>
>>
>>
>> --
>> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>> For additional commands, e-mail: <ma...@jakarta.apache.org>
>>
>>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Dynamic string replacement?

Posted by Henri Yandell <ba...@generationjava.com>.
Care to give an example?

Are you suggesting a bean called:

ReplacerBean

with properties

replacerBean.with
replacerBean.replace
replacerBean.text

or some such?

Seems unintuitive.


On Wed, 11 Sep 2002, Vernon Wu wrote:

>
> That can be done by using a Java bean conjoining with JSTL.
>
> 9/11/2002 6:03:47 AM, Eric.Lewis@swissinfo.ch wrote:
>
> >Hi all
> >
> >It looks like I found something to implement in the String Tag Library  :-)
> >
> >What I'm trying to do is to create links within a text, i.e. replacing 'the
> >text' with '<a href="...">the text</a>'. The problem is that both the text
> >and the link are dynamic.
> >However, the String Tag Library won't let me replace things dynamically.
> >
> >Consider this:
> >
> ><c:set var="a" value="This will be replaced"/>
> ><c:set var="b" value="The new text"/>
> ><c:out value="${a}"/><br>
> ><c:out value="${b}"/><br>
> ><str:replace replace="This will be replaced" with="The new text">And he
> >said: "This will be replaced!".</str:replace>
> >
> >will show
> >
> >This will be replaced
> >The new text
> >And he said: "The new text!".
> >
> > - works like a charm! However,
> >
> ><c:set var="a" value="This will be replaced"/>
> ><c:set var="b" value="The new text"/>
> ><c:out value="${a}"/><br>
> ><c:out value="${b}"/><br>
> ><str:replace replace="${a}" with="${b}">And he said: "This will be
> >replaced!".</str:replace>
> >
> >won't replace anything:
> >
> >This will be replaced
> >The new text
> >And he said: "This will be replaced!".
> >
> >
> >And
> >
> ><c:set var="a" value="This will be replaced"/>
> ><c:set var="b" value="The new text"/>
> ><c:out value="${a}"/><br>
> ><c:out value="${b}"/><br>
> ><str:replace replace="<c:out value="${a}"/>" with="<c:out
> >value="${b}"/>">And he said: "This will be replaced!".</str:replace>
> >
> >even gives me an exception:
> >
> >javax.servlet.ServletException: /jsp/test.jsp(206,40) Attribute ${a} has no
> >value
> >
> >
> >This would be very, very handy if it worked... actually for all of the
> >String tag library.
> >
> >Thanks & regards,
> >Eric
> >
> >
> >--
> >To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> >For additional commands, e-mail: <ma...@jakarta.apache.org>
> >
> >
>
>
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Dynamic string replacement?

Posted by Vernon Wu <ve...@gatewaytech.com>.
That can be done by using a Java bean conjoining with JSTL.

9/11/2002 6:03:47 AM, Eric.Lewis@swissinfo.ch wrote:

>Hi all
>
>It looks like I found something to implement in the String Tag Library  :-)
>
>What I'm trying to do is to create links within a text, i.e. replacing 'the
>text' with '<a href="...">the text</a>'. The problem is that both the text
>and the link are dynamic.
>However, the String Tag Library won't let me replace things dynamically.
>
>Consider this:
>
><c:set var="a" value="This will be replaced"/>
><c:set var="b" value="The new text"/>
><c:out value="${a}"/><br>
><c:out value="${b}"/><br>
><str:replace replace="This will be replaced" with="The new text">And he
>said: "This will be replaced!".</str:replace>
>
>will show
>
>This will be replaced
>The new text
>And he said: "The new text!".
>
> - works like a charm! However,
>
><c:set var="a" value="This will be replaced"/>
><c:set var="b" value="The new text"/>
><c:out value="${a}"/><br>
><c:out value="${b}"/><br>
><str:replace replace="${a}" with="${b}">And he said: "This will be
>replaced!".</str:replace>
>
>won't replace anything:
>
>This will be replaced
>The new text
>And he said: "This will be replaced!".
>
>
>And
>
><c:set var="a" value="This will be replaced"/>
><c:set var="b" value="The new text"/>
><c:out value="${a}"/><br>
><c:out value="${b}"/><br>
><str:replace replace="<c:out value="${a}"/>" with="<c:out
>value="${b}"/>">And he said: "This will be replaced!".</str:replace>
>
>even gives me an exception:
>
>javax.servlet.ServletException: /jsp/test.jsp(206,40) Attribute ${a} has no
>value
>
>
>This would be very, very handy if it worked... actually for all of the
>String tag library.
>
>Thanks & regards,
>Eric
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>