Ben Pezzei wrote:
> hi
> 
> Hans Bergsten schrieb:
> 
>>Ben Pezzei wrote:
>>
>>>So the perfect way would be: give the String, which contains the
>>>tag, to some method, parse it and return the altered text with
>>>the correct link. how can i give this String to the corresponding
>>>link-tag-class? if possible;)
>>
>  
> 
>>I would suggest that you instead allow regular <a> elements in the
>>text. If the URL must be processed somehow (e.g. expanded with a
>>some special prefix, URL rewritten, etc. your <article:display> can
>>simply parse out the <a> elements, process them and add the result
>>to the output stream. This way the author can use an HTML element
>>she is familiar with, no need to learn a new one.
> 
> 
> yeah, that would be nice, but i cant use the normal <a href..>-tag
> because a link to another doc in the app would point actually
> to some kind of object (which is processed at runtime into an URL)

But you can still use the <a> element if you parse it out and
process it within the tag handler for <article:display>, as opposed
of trying to invoke one tag handler (<a:link) from another (<article:
display>). In this case it's just syntax; something to tell your code
which piece of the string needs processing. The advantage with sticking
to the <a> element would be that the article author is familiar with
HTML. If that's not the case, any syntax that's easy to parse and
unlikely to clash with regular article content will do.

>>If the processing is complex, and if you want to invoke it in other
>>places using the <a:link> action, put it in a separate class that you
>>can use from both the <a:link> and the <article:display> tag handlers.
> 
> 
> yeah, that was also the first thing i thought about. But the point ist
> that i dont want to code something which already exists, so i asked
> the mailinglist.

The tag handler API is not intended for encapsulating reusable code.
Think of it as a JSP specific adapter. The real processing code is
better developed as a separate class that you can call from any number
of tag handlers, or from a servlet, applet, or whatever type of
component you want.

> so basically this is what i tried (in the <article:display>-Class):
> 
> LinkTag t = new LinkTag();
> t.setPageContext(pageContext); [x]
> t.setParent(this);
> t.doStartTag();
> ...and so on till
> t.release();
> 
> [x] the point is that i have to create a PageContext object which
> content(data) is actually the String i read out from the db.
> at least this could be the way i *think* it would be possible.
> 
> well after reading around i doubt this would work

Well, like I said, something like the above is possible. But it's
far from elegant, and I strongly discourage it. Focus on writing
reusable, generic classes for all application functionality first,
and then call methods on those classes from the platform specific
adapters (such as a JSP tag handler) instead. I promise you that this
leads to a much more maintainable and flexible system.

Hans
-- 
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com
JavaServer Pages        http://TheJSPBook.com


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to