You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Steven Yang <ke...@gmail.com> on 2009/05/26 09:06:41 UTC

[S2] Getting property value from Enum

Hi First of all if this question has been ask, I apologize for the double
post. and please refer me to the reference. thanks

I am using 2.1.6.
I have a Enum class Gender
and it has a method getTextKey() which simply returns a key for me to use in
getText() in Action

If in my Action I have

private Gender gender

getter...
setter..

then in my jsp if i use
<s:property value="gender.textKey"/>
I get nothing
(toString is not called)

if i use
<s:property value="gender.getTextKey()"/>

I found that it calls toString() first then calls getTextKey() on it and
result in nothing because there is no method called getTextKey on String.

Is this a bug? or am i missing something?

Thanks

Re: [S2] Getting property value from Enum

Posted by Matt Jiang <ma...@gmail.com>.
Don't worry, we all made this kind of mistake before.
and this would not be the last time.
bless you...

On Tue, May 26, 2009 at 4:47 PM, Steven Yang <ke...@gmail.com> wrote:

> OMG
> I can't believe myself.
> how can i make such a stupid mistake
>
> Sorry guys for wasting your time.
>
> Its all my fault my method name was getTextkey()
> but I kept on using getTextKey() or textKey
> (capital K)
> thats why it never worked
>
> its solved.
>

Re: [S2] Getting property value from Enum

Posted by Steven Yang <ke...@gmail.com>.
OMG
I can't believe myself.
how can i make such a stupid mistake

Sorry guys for wasting your time.

Its all my fault my method name was getTextkey()
but I kept on using getTextKey() or textKey
(capital K)
thats why it never worked

its solved.

Re: [S2] Getting property value from Enum

Posted by Steven Yang <ke...@gmail.com>.
Just want to add some more information
if I do
<s:property value="gender.toString()"/>
<s:property value="gender.name()"/>
<s:property value="gender.cardinal()"/>
I get what is expected.
I guess all native Enum methods are fine.