You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2010/10/14 20:42:18 UTC

Re: Inconsistent output of Java 5 enums

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Oliver,

On 10/14/2010 12:24 PM, Oliver Siegmar wrote:
> On Wednesday 13 October 2010 21:21:33 Christopher Schultz wrote:
>> What do your taglib declarations look like? I've only used the JSTL a
>> little bit, and I found that when you have the wrong taglib URL, things
>> don't work properly.
> 
> This is how I use JSTL core:
> 
> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

That looks like the one that worked properly for me.

I unfortunately know very little about the JSTL and it's interaction
with POJOs. I would expect that value="${enum}" would somehow convert
the value to a String for inclusion into the output stream, and calling
EnumType.toString sounds like the right thing to do.

Can you look at the translated .java file that comes from your sample
.jsp and post what the JSP compiler has generated?

This might be a bug, but I'm not really sure. What if the object is not
an enum?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAky3TwoACgkQ9CaO5/Lv0PDsCwCgqJ0NM6aS0YADrzoHQhB+4ZYg
65kAoJQvuLUaPMjOBVhk2FED/TaLJpWA
=M0y7
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Inconsistent output of Java 5 enums

Posted by Konstantin Kolinko <kn...@gmail.com>.
2010/10/14 Christopher Schultz <ch...@christopherschultz.net>:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Oliver,
>
> On 10/14/2010 12:24 PM, Oliver Siegmar wrote:
>> On Wednesday 13 October 2010 21:21:33 Christopher Schultz wrote:
>>> What do your taglib declarations look like? I've only used the JSTL a
>>> little bit, and I found that when you have the wrong taglib URL, things
>>> don't work properly.
>>
>> This is how I use JSTL core:
>>
>> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
>
> That looks like the one that worked properly for me.
>
> I unfortunately know very little about the JSTL and it's interaction
> with POJOs. I would expect that value="${enum}" would somehow convert
> the value to a String for inclusion into the output stream, and calling
> EnumType.toString sounds like the right thing to do.
>
> Can you look at the translated .java file that comes from your sample
> .jsp and post what the JSP compiler has generated?
>
> This might be a bug, but I'm not really sure. What if the object is not
> an enum?
>

The chapter 1.18.2 of the Expression Language Specification Version
2.1, Final Release - May 8, 2006 (a part of JSR-000245: JSP 2.1)
defines how an EL expression is coerced to a String.

One of the points there is
* "Otherwise, if A is Enum, return A.name()"

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Inconsistent output of Java 5 enums

Posted by Oliver Siegmar <ol...@siegmar.org>.
Hello,

now I tried with jstl-api-1.2.jar and jstl-impl-1.2.jar downloaded from 
https://jstl.dev.java.net/download.html - same result.

Am Friday 15 October 2010 schrieb Christopher Schultz:
> >> Uh... why override the toString method like that?
> > 
> > Well, as written in java.lang.Enum:
> > 
> > An enum type should override this method when a more
> > "programmer-friendly" string form exists.
> 
> Fair enough. I feel like VALID versus INVALID (which could be confusing
> in this case) would be plenty programmer-friendly.

Taht was just a simplified class for demonstration purposes.

> >>> The thing is, that EL is using the name() method to print the enum and
> >>> JSTL is using toString(). I did not expect a different enum treatment
> >>> here.
> >> 
> >> If you need it to emit the same thing, doing:
> >> 
> >> <c:out value="${myEnumValue.name}"/>
> > 
> > No, because that would call a method getName() which doesn't exist - the
> > method is named name().
> 
> <c:out value="${myEnumValue.getName()}"/>

You can't do that (at least not with Tomcat 6.0.29).

> Or, just consistently use EL, since that actually works as you expect.

Well...it is again just a simplified example.


Bye

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Inconsistent output of Java 5 enums

Posted by Pid * <pi...@pidster.com>.
On 15 Oct 2010, at 17:42, Oliver Siegmar <ol...@siegmar.org> wrote:

> Pid,
>
> Am Friday 15 October 2010 schrieb Pid:
>>>> No, because that would call a method getName() which doesn't exist - the
>>>> method is named name().
>>>
>>> <c:out value="${myEnumValue.getName()}"/>
>>
>> I don't think that'll work in 6.0.
>
> That's right.
>
>>> Or, just consistently use EL, since that actually works as you expect.
>>
>> +1  '<c:out' seems surplus.
>
> And how do you escape XML characters to entity codes using pure EL?

JSTL Function?

I can't remember the exact syntax.

${fn:escapeXml(my.attribute)}


p

>
>
> Bye
>
> Oliver
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Inconsistent output of Java 5 enums

Posted by Oliver Siegmar <ol...@siegmar.org>.
Chris,

Am Friday 15 October 2010 schrieb Christopher Schultz:
> > <%@taglib prefix="myLib" uri="http://my-domain.org/customLib"%>
> > 
> > <myLib:customTag value="${myEnum}"/>
> > <myLib:customTag value="foo.${myEnum}.bar"/>
> > 
> > I would expect, that this outputs:
> > 
> > VALID
> > foo.VALID.bar
> > 
> > 
> > The output in catalina.out is very interesting:
> > 
> > VALID
> > foo.VALID result, code 0.bar
> 
> Okay, that might be a bug in Tomcat.
> 
> Weird: I would expect that the JSTL relies on the platform's EL
> implementation to work. So, I don't understand why this works for a bare
> EL expression like ${enum} and not <foo value="${enum}" />

I've created https://issues.apache.org/bugzilla/show_bug.cgi?id=50105


Bye

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Inconsistent output of Java 5 enums

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Oliver,

On 10/15/2010 1:28 PM, Oliver Siegmar wrote:
> The enum is part of a 3rd party lib. And of course, there are several 
> workarounds available, but I want to understand what is happening here and 
> clarify if it's a bug.

Just for the record, this has nothing to do with Tomcat: the bug would
be in the JSTL implementation, which you got from a 3rd-party.

> And it's not just the c:out tag - it also happens with other Tags. For 
> demonstration I've created a custom Tag:

[snip]

>         <attribute>
>             <name>value</name>
>             <required>true</required>
>             <rtexprvalue>true</rtexprvalue>
>         </attribute>

[snip]

> <%@taglib prefix="myLib" uri="http://my-domain.org/customLib"%>
> 
> <myLib:customTag value="${myEnum}"/>
> <myLib:customTag value="foo.${myEnum}.bar"/>
> 
> I would expect, that this outputs:
> 
> VALID
> foo.VALID.bar
> 
> 
> The output in catalina.out is very interesting:
> 
> VALID
> foo.VALID result, code 0.bar

Okay, that might be a bug in Tomcat.

Weird: I would expect that the JSTL relies on the platform's EL
implementation to work. So, I don't understand why this works for a bare
EL expression like ${enum} and not <foo value="${enum}" />

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAky4oAAACgkQ9CaO5/Lv0PBD/ACfS+pevIoCaFI/tkIcc+eCcuNJ
1LUAn3sMZEKtX+uvW8161muWPlLmuUR+
=ug3y
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Inconsistent output of Java 5 enums

Posted by Oliver Siegmar <ol...@siegmar.org>.
Am Saturday 16 October 2010 schrieb Maximilian Stocker:
> Okay. Then while I think it is a bug in tomcat (but it might be tomcat 5
> that has the bug because I still don't 100% understand what it *should*
> do) I am not sure what the problem is.
> 
> Do you want the toString value or the name() value? If it's the name value
> then there is no danger in using it outside of c:out anyway because I am
> pretty sure you can't use characters that would need to be escaped as enum
> labels to begin with. And if it's the toString then c:out is using it...

I think, that name() should be used all the time, because of section 1.18.2 of 
the 2.1 JSP-EL spec.

My real usage scenario is, that I'm using Spring's message tag to output a 
message from a ResourceBundle.

<spring:message code="enums.${myEnumValue}"/>

But Tomcat calls the setCode() method with 
"enums.myEnumToStringRepresentation" instead of 
"enums.myEnumNameRepresentation". Because the toString() representation 
includes whitespaces and other special characters that doesn't work well. Of 
course I can find workarounds, but I wanted to discuss if this is a bug or 
not.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Inconsistent output of Java 5 enums

Posted by Maximilian Stocker <ma...@talentoyster.com>.
Okay. Then while I think it is a bug in tomcat (but it might be tomcat 5 that has the bug because I still don't 100% understand what it *should* do) I am not sure what the problem is.

Do you want the toString value or the name() value? If it's the name value then there is no danger in using it outside of c:out anyway because I am pretty sure you can't use characters that would need to be escaped as enum labels to begin with. And if it's the toString then c:out is using it...

-----Original Message-----
From: Oliver Siegmar [mailto:oliver@siegmar.org]
Sent: Friday, October 15, 2010 5:42 PM
To: Tomcat Users List
Subject: Re: Inconsistent output of Java 5 enums

Am Friday 15 October 2010 schrieb Maximilian Stocker:
> On tomcat 5.5. I get
>
> #1 = A is for Apple
> #2 = A is for Apple
>
> On tomcat 6 I get
>
> #1 = APPLE
> #2 = A is for Apple
>
> Which is obviously not the same, and surprised me, but it seems if I
> understand this thread that it is the opposite of what you are seeing and
> that I really don't understand.

No, that's exactly the same here.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Inconsistent output of Java 5 enums

Posted by Oliver Siegmar <ol...@siegmar.org>.
Am Friday 15 October 2010 schrieb Maximilian Stocker:
> On tomcat 5.5. I get
> 
> #1 = A is for Apple
> #2 = A is for Apple
> 
> On tomcat 6 I get
> 
> #1 = APPLE
> #2 = A is for Apple
> 
> Which is obviously not the same, and surprised me, but it seems if I
> understand this thread that it is the opposite of what you are seeing and
> that I really don't understand.

No, that's exactly the same here.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Inconsistent output of Java 5 enums

Posted by Maximilian Stocker <ma...@talentoyster.com>.
I did some testing myself just now with a simple enum and I think this is a Tomcat bug somewhere. Whether the old behaviour was right or wrong vs the new I don't know. I also think that your enum is screwy or doing something different then you think.

At any rate I created a simple enum

public enum Fruit{APPLE,ORANGE,BANANA;

        public String toString(){
                switch(this){
                case APPLE:
                        return "A is for Apple";
                case ORANGE:
                        return "O is for Orange";
                default:
                                return "B is for Banana";
                }
        }
}

I then used the following in a JSP (enumtest is a simple model object with a Fruit property set to Fruit.APPLE)

#1 = ${enumtest.fruit}
<br>
#2 = <c:out value="${enumtest.fruit}"/>


On tomcat 5.5. I get

#1 = A is for Apple
#2 = A is for Apple

On tomcat 6 I get

#1 = APPLE
#2 = A is for Apple

Which is obviously not the same, and surprised me, but it seems if I understand this thread that it is the opposite of what you are seeing and that I really don't understand.




-----Original Message-----
From: Oliver Siegmar [mailto:oliver@siegmar.org]
Sent: Friday, October 15, 2010 1:29 PM
To: Tomcat Users List
Subject: Re: Inconsistent output of Java 5 enums

Hello,

Am Friday 15 October 2010 schrieb Maximilian Stocker:
> > > Or, just consistently use EL, since that actually works as you expect.
> >
> > +1  '<c:out' seems surplus.
>
> And how do you escape XML characters to entity codes using pure EL?
>
> This seems a valid reason except that is this a problem for your enum?

As stated before, it was just a simplified example.

> If it really is a problem then did you try and create a new getter method
> that returns your to string content in the enum? And then call that with
> c:out.

The enum is part of a 3rd party lib. And of course, there are several
workarounds available, but I want to understand what is happening here and
clearify if it's a bug.

And it's not just the c:out tag - it also happens with other Tags. For
demonstration I've created a custom Tag:


public class MyCustomTag implements Tag {

    public void setValue(String value) {
        System.out.println(value);
    }

    @Override
    public void setPageContext(PageContext pc) {
    }

    @Override
    public void setParent(Tag t) {
    }

    @Override
    public Tag getParent() {
        return null;
    }

    @Override
    public int doStartTag() throws JspException {
        return SKIP_BODY;
    }

    @Override
    public int doEndTag() throws JspException {
        return EVAL_PAGE;
    }

    @Override
    public void release() {
    }

}

My TLD:

<?xml version="1.0" encoding="UTF-8" ?>
<taglib xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-
jsptaglibrary_2_1.xsd" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1">
    <tlibversion>1.0</tlibversion>
    <uri>http://my-domain.org/customLib</uri>
    <tag>
        <name>customTag</name>
        <tagclass>mypackage.MyCustomTag</tagclass>
        <bodycontent>empty</bodycontent>
        <attribute>
            <name>value</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>
</taglib>




And in my JSP file is use it:

<%@taglib prefix="myLib" uri="http://my-domain.org/customLib"%>

<myLib:customTag value="${myEnum}"/>
<myLib:customTag value="foo.${myEnum}.bar"/>

I would expect, that this outputs:

VALID
foo.VALID.bar


The output in catalina.out is very interesting:

VALID
foo.VALID result, code 0.bar


Remember, VALID is the enum name() and "VALID result, code 0" is the enum
toString(). I think that is REALLY weird...


Bye

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Inconsistent output of Java 5 enums

Posted by Oliver Siegmar <ol...@siegmar.org>.
Hello,

Am Friday 15 October 2010 schrieb Maximilian Stocker:
> > > Or, just consistently use EL, since that actually works as you expect.
> > 
> > +1  '<c:out' seems surplus.
> 
> And how do you escape XML characters to entity codes using pure EL?
> 
> This seems a valid reason except that is this a problem for your enum?

As stated before, it was just a simplified example.

> If it really is a problem then did you try and create a new getter method
> that returns your to string content in the enum? And then call that with
> c:out.

The enum is part of a 3rd party lib. And of course, there are several 
workarounds available, but I want to understand what is happening here and 
clearify if it's a bug.

And it's not just the c:out tag - it also happens with other Tags. For 
demonstration I've created a custom Tag:


public class MyCustomTag implements Tag {

    public void setValue(String value) {
        System.out.println(value);
    }

    @Override
    public void setPageContext(PageContext pc) {
    }

    @Override
    public void setParent(Tag t) {
    }

    @Override
    public Tag getParent() {
        return null;
    }

    @Override
    public int doStartTag() throws JspException {
        return SKIP_BODY;
    }

    @Override
    public int doEndTag() throws JspException {
        return EVAL_PAGE;
    }

    @Override
    public void release() {
    }

}

My TLD:

<?xml version="1.0" encoding="UTF-8" ?>
<taglib xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-
jsptaglibrary_2_1.xsd" xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1">
    <tlibversion>1.0</tlibversion>
    <uri>http://my-domain.org/customLib</uri>
    <tag>
        <name>customTag</name>
        <tagclass>mypackage.MyCustomTag</tagclass>
        <bodycontent>empty</bodycontent>
        <attribute>
            <name>value</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>
</taglib>




And in my JSP file is use it:

<%@taglib prefix="myLib" uri="http://my-domain.org/customLib"%>

<myLib:customTag value="${myEnum}"/>
<myLib:customTag value="foo.${myEnum}.bar"/>

I would expect, that this outputs:

VALID
foo.VALID.bar


The output in catalina.out is very interesting:

VALID
foo.VALID result, code 0.bar


Remember, VALID is the enum name() and "VALID result, code 0" is the enum 
toString(). I think that is REALLY weird...


Bye

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Inconsistent output of Java 5 enums

Posted by Maximilian Stocker <ma...@talentoyster.com>.
> > Or, just consistently use EL, since that actually works as you expect.
>
> +1  '<c:out' seems surplus.

And how do you escape XML characters to entity codes using pure EL?

This seems a valid reason except that is this a problem for your enum?

If it really is a problem then did you try and create a new getter method that returns your to string content in the enum? And then call that with c:out.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Inconsistent output of Java 5 enums

Posted by Oliver Siegmar <ol...@siegmar.org>.
Pid,

Am Friday 15 October 2010 schrieb Pid:
> >> No, because that would call a method getName() which doesn't exist - the
> >> method is named name().
> > 
> > <c:out value="${myEnumValue.getName()}"/>
> 
> I don't think that'll work in 6.0.

That's right.

> > Or, just consistently use EL, since that actually works as you expect.
> 
> +1  '<c:out' seems surplus.

And how do you escape XML characters to entity codes using pure EL?


Bye

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Inconsistent output of Java 5 enums

Posted by Pid <pi...@pidster.com>.
On 15/10/2010 15:22, Christopher Schultz wrote:
> Oliver,
> 
> On 10/15/2010 10:19 AM, Oliver Siegmar wrote:
>> Chris,
> 
>> On Friday 15 October 2010 16:11:29 Christopher Schultz wrote:
>>>> not. Sorry for the confusion. So this is a simplified example for my enum:
>>> You're right: that was stupid of me. I had forgotten your toString method.
>>>
>>> Uh... why override the toString method like that?
> 
>> Well, as written in java.lang.Enum:
> 
>> An enum type should override this method when a more "programmer-friendly" 
>> string form exists.
> 
> Fair enough. I feel like VALID versus INVALID (which could be confusing
> in this case) would be plenty programmer-friendly.
> 
>>>> The thing is, that EL is using the name() method to print the enum and
>>>> JSTL is using toString(). I did not expect a different enum treatment
>>>> here.
>>>
>>> If you need it to emit the same thing, doing:
>>>
>>> <c:out value="${myEnumValue.name}"/>
> 
>> No, because that would call a method getName() which doesn't exist - the 
>> method is named name().
> 
> <c:out value="${myEnumValue.getName()}"/>

I don't think that'll work in 6.0.

> Or, just consistently use EL, since that actually works as you expect.

+1  '<c:out' seems surplus.


p

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



Re: Inconsistent output of Java 5 enums

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Oliver,

On 10/15/2010 10:19 AM, Oliver Siegmar wrote:
> Chris,
> 
> On Friday 15 October 2010 16:11:29 Christopher Schultz wrote:
>>> not. Sorry for the confusion. So this is a simplified example for my enum:
>> You're right: that was stupid of me. I had forgotten your toString method.
>>
>> Uh... why override the toString method like that?
> 
> Well, as written in java.lang.Enum:
> 
> An enum type should override this method when a more "programmer-friendly" 
> string form exists.

Fair enough. I feel like VALID versus INVALID (which could be confusing
in this case) would be plenty programmer-friendly.

>>> The thing is, that EL is using the name() method to print the enum and
>>> JSTL is using toString(). I did not expect a different enum treatment
>>> here.
>>
>> If you need it to emit the same thing, doing:
>>
>> <c:out value="${myEnumValue.name}"/>
> 
> No, because that would call a method getName() which doesn't exist - the 
> method is named name().

<c:out value="${myEnumValue.getName()}"/>

?

Or, just consistently use EL, since that actually works as you expect.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAky4Y7MACgkQ9CaO5/Lv0PAeewCdGjswzmpXGShPgpLnYtt74CDv
Y04AoJkjy6pgZyXQuvMsA5SFv9HpAQaH
=pZSv
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Inconsistent output of Java 5 enums

Posted by Oliver Siegmar <ol...@siegmar.org>.
Chris,

On Friday 15 October 2010 16:11:29 Christopher Schultz wrote:
> > not. Sorry for the confusion. So this is a simplified example for my enum:
> You're right: that was stupid of me. I had forgotten your toString method.
> 
> Uh... why override the toString method like that?

Well, as written in java.lang.Enum:

An enum type should override this method when a more "programmer-friendly" 
string form exists.

> > The thing is, that EL is using the name() method to print the enum and
> > JSTL is using toString(). I did not expect a different enum treatment
> > here.
> 
> If you need it to emit the same thing, doing:
> 
> <c:out value="${myEnumValue.name}"/>

No, because that would call a method getName() which doesn't exist - the 
method is named name().


Bye

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Inconsistent output of Java 5 enums

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Oliver,

On 10/15/2010 1:40 AM, Oliver Siegmar wrote:
> Am Thursday 14 October 2010 schrieb Christopher Schultz:
>> So I'm surprised that Oliver is getting that weird output.
> 
> I wrote in my initial mail to this list "I have an enum that has an overridden 
> toString() method". I thought it was clear what that means, obviously it was 
> not. Sorry for the confusion. So this is a simplified example for my enum:

You're right: that was stupid of me. I had forgotten your toString method.

Uh... why override the toString method like that?

> The thing is, that EL is using the name() method to print the enum and JSTL is 
> using toString(). I did not expect a different enum treatment here.

If you need it to emit the same thing, doing:

<c:out value="${myEnumValue.name}"/>

...will certainly work across these versions.

> One possible explaination is that Pid is right when he says "The related 
> sources jar was built in 2006, and the pom for that indicates that it's 
> dependent on JSP 2.0, rather than 2.1". Does anyone know if a true JSTL 1.2 
> using JSP 2.1 is available in the maven repository? Anyway I will try a 
> manually downloaded version tonight.

Try getting it from the canonical https://jstl.dev.java.net/, and ask
them about their Maven repo submission.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAky4YREACgkQ9CaO5/Lv0PDH8wCglvc2kcXjbc1ktxQdvOW5UOxl
OTkAoLzly4kRGfrWiPTvLvLHV7hEuH3+
=ClL+
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Inconsistent output of Java 5 enums

Posted by Oliver Siegmar <ol...@siegmar.org>.
Hi all,

Am Thursday 14 October 2010 schrieb Christopher Schultz:
> So I'm surprised that Oliver is getting that weird output.

I wrote in my initial mail to this list "I have an enum that has an overridden 
toString() method". I thought it was clear what that means, obviously it was 
not. Sorry for the confusion. So this is a simplified example for my enum:

public enum MyEnum {

    VALID(0),
    INVALID(1);

    private final int code;

    private MyEnum(int code) {
        this.code = code;
    }

    @Override
    public String toString() {
        return name() + " result, code: " + code;
    }

}


My JSP looks like this:

Output per EL: ${myEnumValue} <br/>
Output per JSTL: <c:out value="${myEnumValue}"/>


The output is:

Output per EL: VALID
Output per JSTL: VALID result, code 0


The thing is, that EL is using the name() method to print the enum and JSTL is 
using toString(). I did not expect a different enum treatment here.


One possible explaination is that Pid is right when he says "The related 
sources jar was built in 2006, and the pom for that indicates that it's 
dependent on JSP 2.0, rather than 2.1". Does anyone know if a true JSTL 1.2 
using JSP 2.1 is available in the maven repository? Anyway I will try a 
manually downloaded version tonight.



Bye

Oliver


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Inconsistent output of Java 5 enums

Posted by Pid <pi...@pidster.com>.
On 14/10/2010 20:31, Christopher Schultz wrote:
> All,
> 
> On 10/14/2010 3:24 PM, Christopher Schultz wrote:
>> Pid,
> 
>> On 10/14/2010 3:21 PM, Pid wrote:
>>> On 14/10/2010 20:03, Oliver Siegmar wrote:
>>>> Hi Pid,
>>>>
>>>> Am Thursday 14 October 2010 schrieb Pid:
>>>>> Which JSTL implementation are you using and which Java version was it
>>>>> compiled for/on?
>>>>
>>>> http://repo2.maven.org/maven2/javax/servlet/jstl/1.2/jstl-1.2.jar
>>>>
>>>> Using Sun/Oracle Java 6u21
> 
>>> OK.
> 
>>> The related sources jar was built in 2006, and the pom for that
>>> indicates that it's dependent on JSP 2.0, rather than 2.1.
> 
>>> At a guess, JSTL doesn't know what an enum is, so it's just doing what
>>> it would do for any other unknown Object subclass, and is calling the
>>> .toString() method.
> 
>> Something I didn't bother asking: what does the default Enum.toString
>> return?
> 
> Answer to my own question:
> 
> public class EnumTest
> {
>   public enum Weekday {
>     SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
>   }
> 
>   public static void main(String[] args)
>   {
>     System.out.println(Weekday.SUNDAY);
>   }
> }
> 
> This produces "SUNDAY" as output.
> 
> The EnumTest.Weekday "class" doesn't override the toString method,
> allowing java.lang.Enum (it's superclass) to handle that.
> 
> java.lang.Enum.toString is implemented like this:
> 
> public String toString()
> {
>   return name;
> }
> 
> ... and "name" is a String which is initialized in the constructor (when
> I decompile EnumTest.Weekday, I can see it uses the string "Sunday", as
> one might expect).
> 
> So I'm surprised that Oliver is getting that weird output.

He's overriden the .toString method, no?

EL must be recognising it's an Enum and treating it differently.
There's a spec for that, so it'll probably define what to do with an Enum.


p

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



Re: Inconsistent output of Java 5 enums

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

All,

On 10/14/2010 3:24 PM, Christopher Schultz wrote:
> Pid,
> 
> On 10/14/2010 3:21 PM, Pid wrote:
>> On 14/10/2010 20:03, Oliver Siegmar wrote:
>>> Hi Pid,
>>>
>>> Am Thursday 14 October 2010 schrieb Pid:
>>>> Which JSTL implementation are you using and which Java version was it
>>>> compiled for/on?
>>>
>>> http://repo2.maven.org/maven2/javax/servlet/jstl/1.2/jstl-1.2.jar
>>>
>>> Using Sun/Oracle Java 6u21
> 
>> OK.
> 
>> The related sources jar was built in 2006, and the pom for that
>> indicates that it's dependent on JSP 2.0, rather than 2.1.
> 
>> At a guess, JSTL doesn't know what an enum is, so it's just doing what
>> it would do for any other unknown Object subclass, and is calling the
>> .toString() method.
> 
> Something I didn't bother asking: what does the default Enum.toString
> return?

Answer to my own question:

public class EnumTest
{
  public enum Weekday {
    SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
  }

  public static void main(String[] args)
  {
    System.out.println(Weekday.SUNDAY);
  }
}

This produces "SUNDAY" as output.

The EnumTest.Weekday "class" doesn't override the toString method,
allowing java.lang.Enum (it's superclass) to handle that.

java.lang.Enum.toString is implemented like this:

public String toString()
{
  return name;
}

... and "name" is a String which is initialized in the constructor (when
I decompile EnumTest.Weekday, I can see it uses the string "Sunday", as
one might expect).

So I'm surprised that Oliver is getting that weird output.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAky3Wn4ACgkQ9CaO5/Lv0PB1yACeKEbeavY+ois6H2BMndqRLWsm
CxEAn0SsiuLsvv6O/Szd3QKsPZ66Mxgj
=bQGI
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Inconsistent output of Java 5 enums

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Pid,

On 10/14/2010 3:21 PM, Pid wrote:
> On 14/10/2010 20:03, Oliver Siegmar wrote:
>> Hi Pid,
>>
>> Am Thursday 14 October 2010 schrieb Pid:
>>> Which JSTL implementation are you using and which Java version was it
>>> compiled for/on?
>>
>> http://repo2.maven.org/maven2/javax/servlet/jstl/1.2/jstl-1.2.jar
>>
>> Using Sun/Oracle Java 6u21
> 
> OK.
> 
> The related sources jar was built in 2006, and the pom for that
> indicates that it's dependent on JSP 2.0, rather than 2.1.
> 
> At a guess, JSTL doesn't know what an enum is, so it's just doing what
> it would do for any other unknown Object subclass, and is calling the
> .toString() method.

Something I didn't bother asking: what does the default Enum.toString
return?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAky3WM8ACgkQ9CaO5/Lv0PA1dgCghEZM8Y1K+hWs+jH6mUqGau4W
uz8An1VCUaS60Af2T8L54dd2c05tgQmf
=yrfV
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Inconsistent output of Java 5 enums

Posted by Pid <pi...@pidster.com>.
On 14/10/2010 20:03, Oliver Siegmar wrote:
> Hi Pid,
> 
> Am Thursday 14 October 2010 schrieb Pid:
>> Which JSTL implementation are you using and which Java version was it
>> compiled for/on?
> 
> http://repo2.maven.org/maven2/javax/servlet/jstl/1.2/jstl-1.2.jar
> 
> Using Sun/Oracle Java 6u21

OK.

The related sources jar was built in 2006, and the pom for that
indicates that it's dependent on JSP 2.0, rather than 2.1.

At a guess, JSTL doesn't know what an enum is, so it's just doing what
it would do for any other unknown Object subclass, and is calling the
.toString() method.


p


Re: Inconsistent output of Java 5 enums

Posted by Oliver Siegmar <ol...@siegmar.org>.
Hi Pid,

Am Thursday 14 October 2010 schrieb Pid:
> Which JSTL implementation are you using and which Java version was it
> compiled for/on?

http://repo2.maven.org/maven2/javax/servlet/jstl/1.2/jstl-1.2.jar

Using Sun/Oracle Java 6u21


Bye

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Inconsistent output of Java 5 enums

Posted by Martin Gainty <mg...@hotmail.com>.
as of J2SE5 enum is a J2SE keyword 
 
http://en.wikibooks.org/wiki/Java_Programming/Keywords/enum

hth
Martin 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.



 

> Date: Thu, 14 Oct 2010 19:50:42 +0100
> From: pid@pidster.com
> To: users@tomcat.apache.org
> Subject: Re: Inconsistent output of Java 5 enums
> 
> On 14/10/2010 19:42, Christopher Schultz wrote:
> > Oliver,
> > 
> > On 10/14/2010 12:24 PM, Oliver Siegmar wrote:
> >> On Wednesday 13 October 2010 21:21:33 Christopher Schultz wrote:
> >>> What do your taglib declarations look like? I've only used the JSTL a
> >>> little bit, and I found that when you have the wrong taglib URL, things
> >>> don't work properly.
> > 
> >> This is how I use JSTL core:
> > 
> >> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
> > 
> > That looks like the one that worked properly for me.
> > 
> > I unfortunately know very little about the JSTL and it's interaction
> > with POJOs. I would expect that value="${enum}" would somehow convert
> > the value to a String for inclusion into the output stream, and calling
> > EnumType.toString sounds like the right thing to do.
> > 
> > Can you look at the translated .java file that comes from your sample
> > .jsp and post what the JSP compiler has generated?
> > 
> > This might be a bug, but I'm not really sure. What if the object is not
> > an enum?
> 
> Which JSTL implementation are you using and which Java version was it
> compiled for/on?
> 
> 
> p
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
 		 	   		  

Re: Inconsistent output of Java 5 enums

Posted by Pid <pi...@pidster.com>.
On 14/10/2010 19:42, Christopher Schultz wrote:
> Oliver,
> 
> On 10/14/2010 12:24 PM, Oliver Siegmar wrote:
>> On Wednesday 13 October 2010 21:21:33 Christopher Schultz wrote:
>>> What do your taglib declarations look like? I've only used the JSTL a
>>> little bit, and I found that when you have the wrong taglib URL, things
>>> don't work properly.
> 
>> This is how I use JSTL core:
> 
>> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
> 
> That looks like the one that worked properly for me.
> 
> I unfortunately know very little about the JSTL and it's interaction
> with POJOs. I would expect that value="${enum}" would somehow convert
> the value to a String for inclusion into the output stream, and calling
> EnumType.toString sounds like the right thing to do.
> 
> Can you look at the translated .java file that comes from your sample
> .jsp and post what the JSP compiler has generated?
> 
> This might be a bug, but I'm not really sure. What if the object is not
> an enum?

Which JSTL implementation are you using and which Java version was it
compiled for/on?


p


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org