JSF error: component property class is not writable
November 10, 2011 20:33:46 Last update: November 10, 2011 20:33:46
The stack trace is like this:
You get this error because you are using the
If you can add a tag handler to the UI component, you can alias
java.lang.IllegalArgumentException: Component property class is not writable at javax.faces.component._ComponentAttributesMap.setComponentProperty(_ComponentAttributesMap.java:518) at javax.faces.component._ComponentAttributesMap.put(_ComponentAttributesMap.java:401) at javax.faces.component._ComponentAttributesMap.put(_ComponentAttributesMap.java:58) at org.apache.myfaces.view.facelets.tag.jsf.ComponentRule$LiteralAttributeMetadata.applyMetadata(ComponentRule.java:52) at org.apache.myfaces.view.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:45) at javax.faces.view.facelets.MetaTagHandler.setAttributes(MetaTagHandler.java:68) at javax.faces.view.facelets.DelegatingMetaTagHandler.setAttributes(DelegatingMetaTagHandler.java:93)
You get this error because you are using the
class attribute with a JSF UI component, for which the class attribute cannot be altered. Of course you meant CSS class, not Java class! You can use the styleClass attribute instead of the class attribute. The styleClass attribute becomes the class attribute when the component is rendered.
If you can add a tag handler to the UI component, you can alias
class to styleClass, which will allow you to use the class attribute on the UI component:
import javax.faces.view.facelets.*; public class MyTagHandler extends ComponentHandler { public MyTagHandler(ComponentConfig config) { super(config); } @Override protected MetaRuleset createMetaRuleset(Class cls) { MetaRuleset meta = super.createMetaRuleset(cls); meta.alias("class", "styleClass"); return meta; } }