0

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.

Community
  • 1
  • 1
Tomestos
  • 48
  • 8
  • I think http://stackoverflow.com/questions/16666472/custom-html-tag-attributes-are-not-rendered-by-jsf will help you. Html5RenderKit in the OmniFaces project espacially looks promising: https://snapshot-omnifaces.rhcloud.com/renderkits/Html5RenderKit – Magnilex Aug 19 '13 at 13:47
  • 1
    Since I'm not able to update to JSF 2.2 I found this [article](http://stackoverflow.com/questions/14928912/using-bootstrap-related-tags-inside-jsf2-hinputtext-component) very useful. Thx, Magnilex, you made my day! – Tomestos Aug 19 '13 at 14:07

0 Answers0