You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by Mujahid Ali <ma...@leftbrain.com> on 2006/03/16 23:56:14 UTC

Property Editor

I posted this message on the user list but I don't see any activity so 
figured I try my luck here...

I have a custom tag in which I am evaluating an attribute as follow:

(Locale)ExpressionEvaluatorManager.evaluate("locale", expr, 
Locale.class, this, pageContext)

But I get an error:

javax.servlet.jsp.JspException: An error occurred while evaluating 
custom action attribute "locale" with value "en_US": Attempt to convert 
String "en_US" to type "java.util.Locale", but there is no 
PropertyEditor for that type (null)
    at org.apache.taglibs.standard.lang.jstl.Evaluator.evaluate(Unknown 
Source)
    at org.apache.taglibs.standard.lang.jstl.Evaluator.evaluate(Unknown 
Source)
    at 
org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager.evaluate(Unknown 
Source)


I am using standard.jar (v 1.1).

If I want to convert a String to Locale object, I assume I need to 
define some sort of PropertyEditor??

Also, this code used to work against standard.jar (1.0)...(not sure if 
ex-developer at our work modified it or not...)

Any help is appreciated.

Thanks,

Mujahid


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org


Re: Property Editor

Posted by Rahul Akolkar <ra...@gmail.com>.
On 3/17/06, Mujahid Ali <ma...@leftbrain.com> wrote:
<snip/>
>
> In JSP 2.0/JSTL 1.1,  the "expr" passed is *already* evaluated and
> contains  a value of  "en_US"  (result of Locale.toString())
> and the above code fails because we are expecting a Locale, but a String
> value is found.
>
<snap/>

Which is why we have upto three flavors (w/ el and rt) sub 2.0 ;-)


> So if this is the case of expressions being pre-evaluated before the tag
> handlers can do anything, then what is the point of writing your own tags?
>
> Maybe I am missing something...
>
<snip/>

A tag can do more than just evaluate its attribute values.

-Rahul


> Thanks,
>
> Muajhid
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org


Re: Property Editor

Posted by Mujahid Ali <ma...@leftbrain.com>.
My apologies for not waiting long enough. Just been stuck on this 
problem for couple of days now so just bit frustrated.
I get your point, and as it turns out, I *am* passing a locale and 
should be expecting a locale back.

I think I have figured out why I am getting the error, just wanted to 
run by you guys first.

Its my understanding that under JSP 2.0, the expression evaluation is 
handled by the JSP engine and not the JSTL engine. In JSP 1.2/JSTL 1.0, 
expression evaluation was handled by the JSTL engine.

So, suppose if I have a tag:

<me:report loacle=${contact.loacle}/>  (contact.locale returns a 
java.util.Locale object)

In JSP 1.2/JSTL 1.0 environment, the handler for the locale attribute:
    public void setLocale(String expr)
        throws JspException
    {
        
this.locale=(Locale)ExpressionEvaluatorManager.evaluate("locale", expr, 
Locale.class, this, pageContext);
    }

the "expr" passed in is ${contact.loacle} which is evaluated to a Locale 
object and the above code works fine.

In JSP 2.0/JSTL 1.1,  the "expr" passed is *already* evaluated and 
contains  a value of  "en_US"  (result of Locale.toString())
and the above code fails because we are expecting a Locale, but a String 
value is found.

So if this is the case of expressions being pre-evaluated before the tag 
handlers can do anything, then what is the point of writing your own tags?

Maybe I am missing something...

Thanks,

Muajhid






Martin Cooper wrote:

>On 3/16/06, Mujahid Ali <ma...@leftbrain.com> wrote:
>  
>
>>I posted this message on the user list
>>    
>>
>
>
>And you waited a whole *four hours* for an answer before posting again!
>Whoa! We're all volunteers here; we're not just sitting around waiting for
>people to ask questions...
>
>In general, tags should be passed the type that their attributes expect,
>rather than magically expecting one type to be morphed to another. In other
>words, if you want to pass a string, then your tag should expect a string.
>If you want the tag to accept a locale, then pass a locale to it.
>
>--
>Martin Cooper
>
>
>but I don't see any activity so
>  
>
>>figured I try my luck here...
>>
>>I have a custom tag in which I am evaluating an attribute as follow:
>>
>>(Locale)ExpressionEvaluatorManager.evaluate("locale", expr,
>>Locale.class, this, pageContext)
>>
>>But I get an error:
>>
>>javax.servlet.jsp.JspException: An error occurred while evaluating
>>custom action attribute "locale" with value "en_US": Attempt to convert
>>String "en_US" to type "java.util.Locale", but there is no
>>PropertyEditor for that type (null)
>>    at org.apache.taglibs.standard.lang.jstl.Evaluator.evaluate(Unknown
>>Source)
>>    at org.apache.taglibs.standard.lang.jstl.Evaluator.evaluate(Unknown
>>Source)
>>    at
>>
>>org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager.evaluate
>>(Unknown
>>Source)
>>
>>
>>I am using standard.jar (v 1.1).
>>
>>If I want to convert a String to Locale object, I assume I need to
>>define some sort of PropertyEditor??
>>
>>Also, this code used to work against standard.jar (1.0)...(not sure if
>>ex-developer at our work modified it or not...)
>>
>>Any help is appreciated.
>>
>>Thanks,
>>
>>Mujahid
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org
>>
>>
>>    
>>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org


Re: Property Editor

Posted by Martin Cooper <ma...@apache.org>.
On 3/16/06, Mujahid Ali <ma...@leftbrain.com> wrote:
>
> I posted this message on the user list


And you waited a whole *four hours* for an answer before posting again!
Whoa! We're all volunteers here; we're not just sitting around waiting for
people to ask questions...

In general, tags should be passed the type that their attributes expect,
rather than magically expecting one type to be morphed to another. In other
words, if you want to pass a string, then your tag should expect a string.
If you want the tag to accept a locale, then pass a locale to it.

--
Martin Cooper


but I don't see any activity so
> figured I try my luck here...
>
> I have a custom tag in which I am evaluating an attribute as follow:
>
> (Locale)ExpressionEvaluatorManager.evaluate("locale", expr,
> Locale.class, this, pageContext)
>
> But I get an error:
>
> javax.servlet.jsp.JspException: An error occurred while evaluating
> custom action attribute "locale" with value "en_US": Attempt to convert
> String "en_US" to type "java.util.Locale", but there is no
> PropertyEditor for that type (null)
>     at org.apache.taglibs.standard.lang.jstl.Evaluator.evaluate(Unknown
> Source)
>     at org.apache.taglibs.standard.lang.jstl.Evaluator.evaluate(Unknown
> Source)
>     at
>
> org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager.evaluate
> (Unknown
> Source)
>
>
> I am using standard.jar (v 1.1).
>
> If I want to convert a String to Locale object, I assume I need to
> define some sort of PropertyEditor??
>
> Also, this code used to work against standard.jar (1.0)...(not sure if
> ex-developer at our work modified it or not...)
>
> Any help is appreciated.
>
> Thanks,
>
> Mujahid
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org
>
>