You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Punyansky, Alex" <Al...@Cybic.com> on 2000/11/03 22:35:50 UTC

PropertyTag question/suggestion

Hi,

I need to write a tag FormatNumberPropertyTag that takes a number from
the bean, formats it and displays it. E.g., the price should have 2
fraction digits and have grouping enable, id number should have no
fraction digits and no grouping. 

I decided to extend the PropertyTag  ( this tag does what I need except
formatting ) by adding a formatType attribute. But the name is defined
as private member variable in PropertyTag and therefore I have to
recreate it in my tag. I could make my tag inherit from BaseInputTag but
I think it makes more sense to inherit from PropertyTag. 
So my questions are :
1. Why the name variable was made private in PropertyTag? Maybe I'm
missing something.
2. Should/Can it be changed to be protected?

P.S. Craig, can you tell me what FWIW means (FWIW, I do
not think of this as a "scriplet" -- it's just a compiler command :-)).
Thanks

Re: PropertyTag question/suggestion

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
"Punyansky, Alex" wrote:

> Hi,
>
> I need to write a tag FormatNumberPropertyTag that takes a number from
> the bean, formats it and displays it. E.g., the price should have 2
> fraction digits and have grouping enable, id number should have no
> fraction digits and no grouping.
>
> I decided to extend the PropertyTag  ( this tag does what I need except
> formatting ) by adding a formatType attribute. But the name is defined
> as private member variable in PropertyTag and therefore I have to
> recreate it in my tag. I could make my tag inherit from BaseInputTag but
> I think it makes more sense to inherit from PropertyTag.
> So my questions are :
> 1. Why the name variable was made private in PropertyTag? Maybe I'm
> missing something.

Because of my (bad?) habits.  I always write my classes initially as "final"
with everything private, and then loosen up on the ones that it makes sense
to subclass.

This is certainly one of them.  I'm going to take a pass through the various
tags and make useful ones for subclassing more appropriate.  This is really
going to happen on the 1.0 code base, as we approach a real release
(finally!!! :-).

By the way, if you'd like to propose your formatting tag for inclusion in
Struts, I'd certainly be interested in looking at it.

>
> 2. Should/Can it be changed to be protected?
>
> P.S. Craig, can you tell me what FWIW means (FWIW, I do
> not think of this as a "scriplet" -- it's just a compiler command :-)).
> Thanks

Sorry about that ... I'm way to used to writing quick messages on mailing
lists :-(

FWIW == For what it's worth

Craig



Re: PropertyTag question/suggestion

Posted by Oleg V Alexeev <go...@penza.net>.
Hello Alex,

Some time ago I write FormatTag inherited from WriteTag. It contains
logic to support i18n for Date and Number objects and additionally
format string can be added to tag parameters. For example -

 <bean:format name="mybean" property="numberPrp" format="##.##" />
 <bean:format name="mybean" property="datePrp" format="yyyy.MM.dd" />

And without format parameter it use current locale from session
attribute ( name in org.apache.struts.Action.LOCALE_KEY ) to convert
Date and Number objects to String.

Saturday, November 04, 2000, 12:35:50 AM, you wrote:

PA> Hi,

PA> I need to write a tag FormatNumberPropertyTag that takes a number from
PA> the bean, formats it and displays it. E.g., the price should have 2
PA> fraction digits and have grouping enable, id number should have no
PA> fraction digits and no grouping. 

PA> I decided to extend the PropertyTag  ( this tag does what I need except
PA> formatting ) by adding a formatType attribute. But the name is defined
PA> as private member variable in PropertyTag and therefore I have to
PA> recreate it in my tag. I could make my tag inherit from BaseInputTag but
PA> I think it makes more sense to inherit from PropertyTag. 
PA> So my questions are :
PA> 1. Why the name variable was made private in PropertyTag? Maybe I'm
PA> missing something.
PA> 2. Should/Can it be changed to be protected?

PA> P.S. Craig, can you tell me what FWIW means (FWIW, I do
PA> not think of this as a "scriplet" -- it's just a compiler command :-)).
PA> Thanks




-- 
Best regards,
 Oleg                            mailto:gonza@penza.net