Subj : Re: E4X: @class causes exception To : McKinley, Richard From : Igor Bukanov Date : Mon Aug 23 2004 08:57 pm 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. > > 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 .