Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

E4X: @class causes exception

1 view
Skip to first unread message

McKinley, Richard

unread,
Aug 23, 2004, 11:54:01 AM8/23/04
to
Trying to use an attribute with the name of "class" (very common in HTML
with CSS) causes and exception:

org.apache.bsf.BSFException: JavaScript Error: missing name after .@
(/report3.jsp#208)
org.apache.bsf.engines.javascript.JavaScriptEngine.handleError(Unknown
Source)
org.apache.bsf.engines.javascript.JavaScriptEngine.eval(Unknown Source)
org.apache.bsf.util.BSFEngineImpl.exec(Unknown Source)
org.apache.taglibs.bsf.scriptlet$1.run(scriptlet.java:101)
java.security.AccessController.doPrivileged(Native Method)
org.apache.taglibs.bsf.scriptlet.doEndTag(scriptlet.java:95)

I realize that class is a reserved word but this is going to be very
common and rather than have it become a FAQ that confuses everyone it
might be better to allow for it.

Regardless, here is the work-around:
//client.@class = "Organization"; //this causes and exception.
client.@tempclass = "Organization";
client.@tempclass.setLocalName("class");

Cheers,

McKinley

Igor Bukanov

unread,
Aug 23, 2004, 1:57:08 PM8/23/04
to McKinley, Richard
McKinley, Richard wrote:
> Trying to use an attribute with the name of "class" (very common in HTML
> with CSS) causes and exception:

See
http://www.mozilla.org/rhino/apidocs/org/mozilla/javascript/Context.html#FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER

To use it do something like the following:

class MyContext extends Context
{
public boolean hasFeature(int featureIndex)
{
if (festureIndex
== FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER)
{
return true;
}
return super.hasFeature();
}
}

Then you need either explicitly construct MyContext and pass it to
Context.enter() or use custom ContextFactory:

class MyFactory extends ContextFactory
{
public Context makeContext()
{
return new MyContext();
}
}

and call once per application:

ContextFactory.initGlobal(new MyFactory());

Then Context.enter() will use MyContext.

0 new messages