JSF Client Side Validators v0.9.1 and Facelets

This version is focused entirely on bug fixes. Unfortunately I could not get the enough free time to add new features and tried to fix the reported bugs instead. Here is the changelog of version 0.9.1.

  • An empty popup was displayed even the input was valid. Fixed.
  • Multi access to global javascript variables was subject to fail. These are converted to local ones.
  • A state saving bug regarding the display mode is fixed.
  • Resource loading is done via the *.jsf mapping instead of /faces/*.
  • Regular expression validator now considers empty input as valid.
  • Instead of document.all, w3c standart document.getElementById is used.
  • Improved example web application demonstrating both validation summary both with and without a popup.

Also if you are a Facelets user, I’ve provided the facelets taglib file as the following;

<?xml version=”1.0″?>
<!DOCTYPE facelet-taglib PUBLIC “-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN” “facelet-taglib_1_0.dtd”>
<facelet-taglib>
<namespace>http://sourceforge.net/projects/jsf-comp/clientvalidators</namespace&gt;
<tag>
    <tag-name>requiredFieldValidator</tag-name>
    <component>
       
<component-type>net.sf.jsfcomp.clientvalidators.requiredfieldvalidator</component-type>
    </component>
</tag>

<tag>
    <tag-name>rangeValidator</tag-name>
    <component>
        <component-type>net.sf.jsfcomp.clientvalidators.rangevalidator</component-type>
    </component>
</tag>

<tag>
    <tag-name>compareValidator</tag-name>
    <component>
        <component-type>net.sf.jsfcomp.clientvalidators.comparevalidator</component-type>
    </component>
</tag>

<tag>
    <tag-name>regularExpressionValidator</tag-name>
    <component>
       
<component-type>net.sf.jsfcomp.clientvalidators.regularexpressionvalidator</component-type>
    </component>
</tag>

<tag>
    <tag-name>lengthValidator</tag-name>
    <component>
        <component-type>net.sf.jsfcomp.clientvalidators.lengthvalidator</component-type>
    </component>
</tag>

<tag>
    <tag-name>customValidator</tag-name>
    <component>
        <component-type>net.sf.jsfcomp.clientvalidators.customvalidator</component-type>
    </component>
</tag>

<tag>
    <tag-name>validationSummary</tag-name>
    <component>
        <component-type>net.sf.jsfcomp.clientvalidators.validationsummary</component-type>
    </component>
</tag>

<tag>
    <tag-name>scriptGenerator</tag-name>
    <component>
        <component-type>net.sf.jsfcomp.clientvalidators.scriptgenerator</component-type>
    </component>
</tag>
</facelet-taglib>

More information on JSF Client Side Validation Library is here. So what is next, I have many other new features in my mind like running the validations onblur-onkeypress other than onsubmit, improving the compare validator(add more operators) and etc. I am currently working on MyFaces Client Side Validation support for tomahawk validators and dont know when I will implement the features I’ve mentioned. Also Acegi’s 1.0.0 version is released and I feel like the time to improve the Acegi-JSF components is near. Moreover someone asked me when the new version of JSF Chart Creator is coming, I had also many ideas on the new version just have not enough time. All of these mean to me just one thing; More nights without sleep, in the end that is the discipline of a “NIGHT DEVELOPER“.

20 Responses to JSF Client Side Validators v0.9.1 and Facelets

  1. Michael says:

    Hi Cagatay,

    don’t know if I am misunderstanding something, but I thought that one does not use the class name in the facelets taglib file. If I use the file above the following error occurs: Undefined component type net.sf.jsfcomp.clientvalidators.rangevalidator.RangeValidator.

    Working taglib file example:


    requiredFieldValidator

    net.sf.jsfcomp.clientvalidators.requiredfieldvalidator

    Where net.sf.jsfcomp.clientvalidators.requiredfieldvalidator comes from faces-config.xml:


    net.sf.jsfcomp.clientvalidators.rangevalidator

    net.sf.jsfcomp.clientvalidators.rangevalidator.RangeValidator

  2. Michael says:

    Correction: net.sf.jsfcomp.clientvalidators.requiredfieldvalidator comes from faces-config.xml:

    net.sf.jsfcomp.clientvalidators.requiredfieldvalidator

    net.sf.jsfcomp.clientvalidators.requiredfieldvalidator.RequiredFieldValidator

  3. Cagatay says:

    Ooops, my bad. I’ve fixed the taglib file now. Thanks for warning me Michael.

  4. Pakin says:

    Hi all!

    I need your help, bacause I’ve just have a problem when using several forms in the same page (f.e. add and edit form). The problem is that I’m not able to validate these forms separately.

    Any idea about how to do this.

    Thanks.

  5. Cagatay says:

    Hi Pakin, I guess the problem is that generated function’s name is same for all the forms although scriptgenerator takes the server id of the form to be generated. The upcoming release will fix this issue.

  6. Pakin says:

    That is!

    It’s exactly what you say, so…when did you say the next version is going to be released?🙂 I told you because for me this bug means getting in troubles.

    Any quickly warkaround? Any suggestion?

    Thanks and regards.

  7. Cagatay says:

    I guess the solution is trivial, instead of writing the function name as clientValidate, the name should be clientValidate_form1 where the prefix is the form to be validated and on form’s submit or button’s onclick the user must change return clientValidate to returnClientValidate_form1. I’ll fix this issue tonight hopefully, and make a new release 0.9.2.

  8. Pakin says:

    If you don’t have enough time I’ll try to send you the code that implements your solution today and you can modify it and package the new version when you want or can🙂
    Send me an email with yours to send the code.

  9. Pakin says:

    Certainly the solution is very trivial, so I think that you don’t need my code😉 unless you want to implement a solution more sofisticated.
    Anyway, I think you should publish a new release with this issue fixed as soon as possible.

    REgards and thanks a lot.

  10. Pari Gandhi says:

    Hi there

    I am a proud user of your jsf-client side validation components and I am very much impressed. Good job!

    One question though:- Is there any way of changing the “yellow” background color that appears on validation errors to something else?

    Ideally the lines below need to change the stylesheet class of the element instead of changing the background color.

    function highlightField(obj) {
    if(document.getElementById(obj) != null)
    document.getElementById(obj).style.backgroundColor=”yellow”;
    }

    function resetFieldColor(obj) {
    if(document.getElementById(obj) != null)

    document.getElementById(obj).style.backgroundColor=”white”;
    }

    Also on the same note,

    I would like to see the following styles moved to a seperate css file (that the user can override if need be) instead of embedding them into every single page.

    Regards

  11. Cagatay says:

    Thanks Pari, Yes there is still a lot todo, and the things you mentioned are already on my todo list.

  12. Dave says:

    Trying to use validator in a tab inside page fragment.
    Trying to use popup for validation messages.
    I think the problem I am having is identifying the “form” property properly.

    Here is the heirarchy:

    Form
    ui:form binding=”#{EnrollStaffMain.form1}” id=”form1″

    Page Fragment inside Div

    Sub View inside page fragment

    TabSet
    ui:tabSet binding=”#{StaffTabPanel.tabSet1}” id=”tabSet1″

    Tab
    ui:tab action=”#{StaffTabPanel.tab1_action}” binding=”#{StaffTabPanel.tab1}” id=”tab1″

    For something like this, what would the form=”…” parameter look like for the popup??

  13. Sr. Cagatay

    The display tag is intended to not display error messages on reserved fields, but only in sumary. In my code it does´nt work. Here is the code:

    It looks to do exactly the oposite: appear on reserved field but not on summary.

    Some idea?
    Tks

  14. Dave says:

    Ok, I’m stuck.

    I’ve done everything at

    http://jsf-comp.sourceforge.net/components/clientvalidators/index.html

    except where it has

    < %@ taglib uri="http://sourceforge.net/projects/jsf-comp/clientvalidators" prefix="cv"%>

    I’ve put

    xmlns:cv=”http://sourceforge.net/projects/jsf-comp/clientvalidators”

    in with my other namespace bits, because I’m using Facelets, not JSP.

    So the clientvalidators-0.9.1.jar is in my webapp/appname/WEB-INF/lib/ directory

    It says this, when I deploy my war:

    Nov 3, 2006 1:42:41 PM com.sun.faces.config.rules.ComponentRule end
    WARNING: [ComponentRule]{faces-config/component} Merge(net.sf.jsfcomp.clientvalidators.requiredfieldvalidator)
    Nov 3, 2006 1:42:41 PM com.sun.faces.config.rules.ComponentRule end
    WARNING: [ComponentRule]{faces-config/component} Merge(net.sf.jsfcomp.clientvalidators.requiredfieldvalidator)

    But then, I load my page which has this defined in it:



    and there’s no javascript in the page to do anything.

    I’ve downloaded the sample-webapp, and that works. I don’t seem to be able to crib from it, though, because it’s using JSPs and I’m not.

    I’d be grateful for any help anyone can give.

    Cheers,

  15. Dave says:

    Replying to myself; I found a different entry about this (telling Google not to omit similar results was the key):

    http://www.jroller.com/page/cagataycivici?entry=jsf_client_side_validators

    the comments helped me out, and Stuff Now Happens for me.

    Cheers,

  16. icess says:

    Hi: civici

    at the Validator web site :
    http://jsf-comp.sourceforge.net/components/clientvalidators/index.html

    about how to use CV.
    you say :

    ——————————————–
    Prefix Mapping
    Resources are loaded from the distribution jar using the default /faces/* prefix, make sure this mapping is defined in web.xml.

    Faces Servlet
    /faces/*

    ——————————
    but , now i find the .js resources do not load through the /faces/* mapping.

    you use .jsf mapping loading the resources.

    the CV generate the following js code.
    …./validatorResource.jsf?name=clientvalidators&type=js

    so, now we must using .jsf mapping . do not need using /faces/* mapping .

    also , if we use .faces mapping . we must add .jsf mapping for using CV.

    YOU can fix this bug. using /Faces/* mapping to load resources , no using .jsf or .faces mapping .

  17. Reda says:

    i have integrated a validator in my jsf page like this:
    . where the page is loaded it return the HTTP 500 error page and in my console i have this error message:”javax.faces.FacesException: Could not get property errorMessage of component _idJsp20″. i think i maked all indications mentioned in the documentation of clientvalidators-0.9.1.jar.
    do you have an idea? thanks

  18. Satya says:

    I am also getting the same error as “Reda” above. I am using MyFaces 1.1.5, Tiles and Tomahawak 1.1.5. If I remove only the below line from my code:

    then the error goes away but no validations obviously. Any idea? Thanks.

  19. Satya says:

    The code was missing from my post above.

  20. Peer says:

    How to Create a Pop up Message Dialog Box using JSF.. Is there any to do this.. ????????

%d bloggers like this: