I want to use a JavaScript framework (named Ideal Forms) together with JSF. This framework uses some special attributes (e.g. "data-ideal
") unknown to JSF. These attributes are removed by JSF's rendering process.
Based on BalusC's code snippet (from stackoverflow) I tried to cheat these attributes into a JSF component:
public class PreRenderViewListener implements SystemEventListener {
@Override
public void processEvent(SystemEvent event) throws AbortProcessingException {
UIViewRoot root = (UIViewRoot) event.getSource();
UIComponent comp = root.findComponent("myForm:myField");
comp.getAttributes().put("style", "width: 100px;");
comp.getAttributes().put("data-ideal", "some_content");
}
...
The xhtml code is
<h:form id="myForm">
<h:inputText id="myField" ... />
</h:form>
The result is
<form id="myForm" name="myForm" ... >
<input id="myForm:myField" type="text" name="myForm:myField" style="width: 100px;" />
</form>
As you see, the first attribute style
(known to h:inputText) is rendered to the client, the second attribute data-ideal
(not known to JSF at all) isn't. Any suggestions how to support jsf-foreign attributes without having to write custom components? Thank you very much.