You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Telmo Costa <te...@ef.pt> on 2007/04/09 18:05:07 UTC

Creating custom struts 2 tags

Hi,

I've been searching for documentation on how to create a custom tag for
struts2, but I haven't succeed. Can you tell me where to find a tutorial or
give me some guidelines on that subject?

I need to create a tag for immediate amount values formatting, as exists for
date values.

Tks a lot



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


RE: Creating custom struts 2 tags

Posted by Telmo Costa <te...@ef.pt>.
Correct... well thought! Struts-core jar includes the struts-tags.tld that
it generated. I created a new tld for my tags, and it worked fine!

Tks a lot!

-----Original Message-----
From: Dave Newton [mailto:newton.dave@yahoo.com] 
Sent: segunda-feira, 9 de Abril de 2007 17:35
To: Struts Users Mailing List
Subject: RE: Creating custom struts 2 tags

--- Telmo Costa <te...@ef.pt> wrote:
> I also changed the annotation to 
> @StrutsTag(name="date2", tldTagClass="my.Date2Tag"
> ...). It compiled fine, but when I try to use it in
> a jsp, it throws "javax.servlet.ServletException:
> /pages/example/Format.jsp(42,2) No tag "date2" 
> defined in tag library imported with prefix
> "s"". I couldn't understand yet how the annotation 
> works, so can you tell me what is wrong?

I'm not sure how the annotation is being processed,
but I would imagine that (at least in the beginning)
define your own TLD for your own custom tags.

The annotation is (probably, anyway?) used to create
the S2 TLD file at build-time.

So you'd either need to duplicate that step, or just
create one manually.

d.



 
____________________________________________________________________________
________
Get your own web address.  
Have a HUGE year through Yahoo! Small Business.
http://smallbusiness.yahoo.com/domains/?p=BESTDEAL

---------------------------------------------------------------------
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: Creating custom struts 2 tags

Posted by Musachy Barroso <mu...@gmail.com>.
Tabletags uses Struts Tags to generate the tld, you can use them also.

musachy

On 4/9/07, Telmo Costa <te...@ef.pt> wrote:
>
> Correct... well thought! Struts-core jar includes the struts-tags.tld that
> it generated. I created a new tld for my tags, and it worked fine!
>
> Tks a lot!
>
> -----Original Message-----
> From: Dave Newton [mailto:newton.dave@yahoo.com]
> Sent: segunda-feira, 9 de Abril de 2007 17:35
> To: Struts Users Mailing List
> Subject: RE: Creating custom struts 2 tags
>
> --- Telmo Costa <te...@ef.pt> wrote:
> > I also changed the annotation to
> > @StrutsTag(name="date2", tldTagClass="my.Date2Tag"
> > ...). It compiled fine, but when I try to use it in
> > a jsp, it throws "javax.servlet.ServletException:
> > /pages/example/Format.jsp(42,2) No tag "date2"
> > defined in tag library imported with prefix
> > "s"". I couldn't understand yet how the annotation
> > works, so can you tell me what is wrong?
>
> I'm not sure how the annotation is being processed,
> but I would imagine that (at least in the beginning)
> define your own TLD for your own custom tags.
>
> The annotation is (probably, anyway?) used to create
> the S2 TLD file at build-time.
>
> So you'd either need to duplicate that step, or just
> create one manually.
>
> d.
>
>
>
>
>
> ____________________________________________________________________________
> ________
> Get your own web address.
> Have a HUGE year through Yahoo! Small Business.
> http://smallbusiness.yahoo.com/domains/?p=BESTDEAL
>
> ---------------------------------------------------------------------
> 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
>
>


-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

RE: Creating custom struts 2 tags

Posted by Dave Newton <ne...@yahoo.com>.
--- Telmo Costa <te...@ef.pt> wrote:
> I also changed the annotation to 
> @StrutsTag(name="date2", tldTagClass="my.Date2Tag"
> ...). It compiled fine, but when I try to use it in
> a jsp, it throws "javax.servlet.ServletException:
> /pages/example/Format.jsp(42,2) No tag "date2" 
> defined in tag library imported with prefix
> "s"". I couldn't understand yet how the annotation 
> works, so can you tell me what is wrong?

I'm not sure how the annotation is being processed,
but I would imagine that (at least in the beginning)
define your own TLD for your own custom tags.

The annotation is (probably, anyway?) used to create
the S2 TLD file at build-time.

So you'd either need to duplicate that step, or just
create one manually.

d.



 
____________________________________________________________________________________
Get your own web address.  
Have a HUGE year through Yahoo! Small Business.
http://smallbusiness.yahoo.com/domains/?p=BESTDEAL

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


RE: Creating custom struts 2 tags

Posted by Telmo Costa <te...@ef.pt>.
Hi, 

That was exactly my first approach: I copied Date and DateTag to my own
package, and renamed them to Date2 and Date2Tag just for testing. I also
changed the annotation to @StrutsTag(name="date2", tldTagClass="my.Date2Tag"
...). It compiled fine, but when I try to use it in a jsp, it throws
"javax.servlet.ServletException: /pages/example/Format.jsp(42,2) No tag
"date2" defined in tag library imported with prefix "s"". I couldn't
understand yet how the annotation works, so can you tell me what is wrong?

Tks

-----Original Message-----
From: Dave Newton [mailto:newton.dave@yahoo.com] 
Sent: segunda-feira, 9 de Abril de 2007 17:16
To: Struts Users Mailing List
Subject: Re: Creating custom struts 2 tags

--- Telmo Costa wrote:
> I've been searching for documentation on how to
> create a custom tag for struts2, but I haven't 
> succeed. Can you tell me where to find a tutorial or
> give me some guidelines on that subject?

They're just like any other custom tags.

Are you referring specifically about how to pull OGNL
values like the S2 tags do?

I'd probably start by looking at the source of
org.apache.struts2.components.Date, since it does what
you want (but for dates :)

I'm guessing if you extend Component you're a *long*
way through the process already; getting the value
appears to be as easy as calling findValue(valueName)
and doing what you need to with it.

That's a good idea for a quick tutorial though; if I
have time I'll add something tonight.

d.



 
____________________________________________________________________________
________
Finding fabulous fares is fun.  
Let Yahoo! FareChase search your favorite travel sites to find flight and
hotel bargains.
http://farechase.yahoo.com/promo-generic-14795097

---------------------------------------------------------------------
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: Creating custom struts 2 tags

Posted by Musachy Barroso <mu...@gmail.com>.
You can check tabletags as an example of creating a plugin with tags:

http://code.google.com/p/tabletags/

regards
musachy

On 4/9/07, Dave Newton <ne...@yahoo.com> wrote:
>
> --- Telmo Costa wrote:
> > I've been searching for documentation on how to
> > create a custom tag for struts2, but I haven't
> > succeed. Can you tell me where to find a tutorial or
> > give me some guidelines on that subject?
>
> They're just like any other custom tags.
>
> Are you referring specifically about how to pull OGNL
> values like the S2 tags do?
>
> I'd probably start by looking at the source of
> org.apache.struts2.components.Date, since it does what
> you want (but for dates :)
>
> I'm guessing if you extend Component you're a *long*
> way through the process already; getting the value
> appears to be as easy as calling findValue(valueName)
> and doing what you need to with it.
>
> That's a good idea for a quick tutorial though; if I
> have time I'll add something tonight.
>
> d.
>
>
>
>
>
> ____________________________________________________________________________________
> Finding fabulous fares is fun.
> Let Yahoo! FareChase search your favorite travel sites to find flight and
> hotel bargains.
> http://farechase.yahoo.com/promo-generic-14795097
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

Re: Creating custom struts 2 tags

Posted by Dave Newton <ne...@yahoo.com>.
--- Telmo Costa wrote:
> I've been searching for documentation on how to
> create a custom tag for struts2, but I haven't 
> succeed. Can you tell me where to find a tutorial or
> give me some guidelines on that subject?

They're just like any other custom tags.

Are you referring specifically about how to pull OGNL
values like the S2 tags do?

I'd probably start by looking at the source of
org.apache.struts2.components.Date, since it does what
you want (but for dates :)

I'm guessing if you extend Component you're a *long*
way through the process already; getting the value
appears to be as easy as calling findValue(valueName)
and doing what you need to with it.

That's a good idea for a quick tutorial though; if I
have time I'll add something tonight.

d.



 
____________________________________________________________________________________
Finding fabulous fares is fun.  
Let Yahoo! FareChase search your favorite travel sites to find flight and hotel bargains.
http://farechase.yahoo.com/promo-generic-14795097

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