How to set minimum length of characters in inputText for bootsfaces? - jsf

I'm trying to use boots-faces for the first time and was looking for some validations at the client side like minimum length, maximum length or exact length.
I was able to find maxLength but I'm struggling to find how to do other length validations. Kindly suggest.

We didn't implement it yet. Please open a feature request at https://github.com/TheCoder4eu/BootsFaces-OSP/issues.
By the way, how do you want the validation messages to be displayed? Currently, maxLength is simply added to the HTML sourcecode. So it's up to the browser to interpret it. In the case of maxLength, that's easy because it suffices to stop accepting input after reaching the maximum length.
minLength, exactLength, and pattern are different. They have to be able to show regular error messages. That amounts to finding the corresponding h:message(s), b:message(s), or p:message(s) tag and populating it with error messages on the client side.
The PrimeFaces team implemented the feature. That was a lot of work, and my perception is that few people miss it. I'd be happy to be proven wrong because the BootsFaces story is all about shifting logic to the client.
In the meantime, just follow the suggestion of #Tiny above and BalusC and use the AJAX engine:
<b:input value="...">
<f:validateLength minimum="..." maximum="..." />
<f:validateRegex pattern="^$|^[A-Za-z-_./\s]{2,50}$" />
</b:input>

Related

Can JSF2 PhaseListener capture input value changes done by hackers during page submit

Am working on JSF2 web application, running the web application in Firefox with Tamper Data tool to test its vulnerability.
When the USer/hacker changes the data for input text or change the multiple selects via Tamper data.
Is there any component in JSF, which can check for this potential hack and check the values that have been changed. I was thinking if anything can be done with PhaseListener, can anybody help with some pointers here.
When the User/hacker changes the data for input text ...
I'm absolutely not understanding why this would be a problem. Perhaps you're talking about disabled or readonly inputs? Well, you don't need to worry about this. JSF will already skip processing when the input has readonly="true" or disabled="true" attributes set in server side.
... or change the multiple selects via Tamper data.
You also don't need to worry about this. JSF will already validate the selected item(s) against the list of available items and generate a Validation Error: Value is not valid in case one of the items doesn't match.
All in all, I have a strong impression that you actually never tried/tested it yourself. You'd better do so before asking a rather rhetorical question and sit back doing nothing.

f:selectItems is there a way to make the key in search work based on the last two digits of a string

Ok I am going to try to work this correctly. I am using primefaces and specifically I am using f:selectItems to create a drop down of dates. Is there a way I can make it so that if someone types in the last two digits of a date it would go to that year.
I.E.
Drop down contains {2001, 2000, 1999, 1998, 1997}
The default behavior is if i typed in 199 it would go to 1999 if I threw an 8 behind that it would go to 1998.
And I want to make it so that if someone types in 97 it would go to 1997.
Is there an easy way to do this?
If you're using h:selectOneMenu and it's just rendering an HTML <select> element, you could possibly do something by hijacking the keypress event. But it seems like a bad idea to break the default browser <select> behavior.
Similar answer / opinion expressed here:
Capture keypress to filter elements

CAPTCHAS and img name /displayed value association

Unfortunately I am having trouble summing up this question in one phrase/line, thus I am forced to initially hint as to what my understanding is before asking the question in fear of me asking a question based on wrong facts or assumptions. As I understand “and please correct me if am wrong”, as I understand captchas work like so:
Have numerous images, and associate each image name/source to its displayed characters value.
Display image, then have user input what they see.
Match user's input against the character value which is associated with that image's name/source.
Assuming my understanding is correct: Given an unlimited amount of time,
Can't one associate image
names/sources with the displayed
characters increasing the chance of
cracking the captcha as they gather
more associations?
In that case, wouldn't the security strength of captchas be parallel the size of the image database?
NOTICE: As i suspected my question was based on wrong understanding.
Short answer! These are dynamic images and they are not stored anywhere. You wont even find them in the source code..
Wikipedia has good explanation about this. Alternatively check out the related questions in SO.
Edit: Goto this page where you can see an example of a captcha. Use firebug to see the HTML code for this image and you will see something like this.
<img height="57" width="300" src="http://www.google.com/recaptcha/api/image?c=03AHJ_VutaG4ahxWuQv0e6edYypp_FM8QuFIZkG75AnAm8iu3WRmwQ41jqcvojmKmbSKXxkf_s9fk61-axEp77_omKZZEYliE35BND_hXNh3Jac6ZUAeD08wOMZPj4W2s-A39vAI84eim5q-z9kFnmoSmon1jG2LmmFw" style="display: block;">
Did you notice the source? It does not point to an image file.
You can copy this url and generate the image (just open it in a browser). So you can develop an application which can download this image and then scan for color change in pixels and try to match for alphabets and numbers but if you notice almost all the alphabets and numbers are connected and closer so it is difficult to seperate different alphabets.
Even if you manage to seperate most of the alphabtes are not perfect. example :
(source: watblog.com)

modx: eForm remembering field input on error

After I submit the form unsuccessfully, the form looses all the values I typed in.
I'm using value="", so that could be related, but if I remove it I get a / in the field, and it still doesn't remember
any idea what I could be doing wrong?
well for now I've used a javascript to do this, it works well but maybe someone has a php/modx/eform solution.
By unsuccessfully submitting the form do you mean it fails validation checks?
No matter what I do, I can't replicate the behaviour you are seeing.
Okay, so I figured it out. I had all the intention of going in and adding the functionality, when I came across line 573 in eform.inc.php "# get SESSION data - thanks to sottwell"
so it's already doing what I want it to.
anyhow, because I couldn't find this in any documentation here is what I've done. Though I must say faintly recall doing this exact thing before. So the next time I need this I might come across this :)
add a value=[+field+]
<input id="femail" name="email" value="[+email+]" eform="Email Address:email:1" />
just remember that the value needs to match the class and NOT the id(unless you want them the same)

how to work around the icefaces ice:selectInputDate validation issue

When using the IceFaces ice:selectInputDate a date selection always triggers the form validation.
So when a user selects a date all validation errors are shown.
That's especially tedious when the date input is at the beginning of the form and all fields are empty. Then the user will get presented with all the "Value missing" error messages.
It's so frustating and really is a shame for such a widely-used framework like IceFaces.
Anybody got any hints how to handle this bug?
http://jira.icefaces.org/browse/ICE-4535
(immediate="true" does not help)
Thanks.
I found out that the real problem is not the getting rid of the validation but that the validation for required="true" is missing completely after a partial submit is sent.
I resolved this here: http://jsfbrickyard.wordpress.com/2010/03/10/how-to-fix-the-requiredtrue-and-partial-submit-problem-in-icefaces/
another and maybe better solution (or workaround) is described in this blog entry:
http://jsfbrickyard.wordpress.com/2010/03/11/a-better-alternative-for-the-icefaces-inputselectinputdate-control/
it describes how to use jquery UI datepicker instead of the ice:selectInputdate control.
comments welcome.

Resources