0

I am using http://parsleyjs.org/ Javascript API for form validation for a JSF form.

I have included Parsley min JS in the header of the page.

An example code for Email validation input text :

 <h:inputText id="userName" class="editText"
value="#{administrator.userName}" data-trigger="change"
data-required="true" data-type="email" />

The tags data-trigger, data-required and data-type are defined for Parsley API.

But JSF removed those tags in the HTML generated.

<input id="j_idt22:userName" type="text" name="j_idt22:userName" class="editText">

What is the way to add those custom tags in HTML generated ?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Parth mehta
  • 1,468
  • 2
  • 23
  • 33
  • 1
    Either you use JSF for HTML generation or you write it yourself. And what happens with unsupported tags, is JSF-implementation dependent. – Web Devie Jul 30 '13 at 11:42
  • ok. so whats the way forward and how should we implement custom tags ? – Parth mehta Jul 30 '13 at 11:47
  • Something like here: http://myjavabuddy.blogspot.de/2013/04/writing-custom-components-for-jsf-20.html – Web Devie Jul 30 '13 at 11:49
  • Apart from the problem (which is easily sovled with a custom renderer or OmniFaces `Html5RenderKit`), why don't you just use JSF builtin validation? Client side validation is hackable/spoofable and completely unreliable. See also http://stackoverflow.com/questions/4013410/jsf2-validation-clientside-or-serverside/ – BalusC Jul 30 '13 at 12:30

1 Answers1

1

You don't need to write your own tags, it is sufficient to write your own renderer for the JSF-tags. A renderer which does not omit your custom attributes.

Look here on how to write & configure such a renderer for all your inputs.

Community
  • 1
  • 1
user1983983
  • 4,793
  • 2
  • 15
  • 24
  • This worked. But on applying the custom tags to input text, the generated HTML gives the tag to its parent element. In my case, its in a table, so the custom tags are assigned to a "td" element containing that input text. So what can be the solution for that ? – Parth mehta Jul 30 '13 at 14:52
  • Even this issue also got solved by using the Renderer class given by @dileks on the link you provided !! – Parth mehta Jul 30 '13 at 15:06