synchronize E mail automatically with database - jsf

I wanted to know from you whether it is possible to check an email entry, if it exists already in the database and to display a message .
This validation should work dynamically without a button.
I work with jsf 2.1 and prime faces 3.5
I hope you understand what I mean and thank you for your help.

You need to implement a custom validator. Full explanation in this guide
Snippet code:
<h:inputText id="email" value="#{bean.email}">
<f:validator validatorId="myEmailValidator" />
<f:ajax event="keyup" render="emailError" />
</h:inputText>
<h:message id="emailError" for="email" />

Related

How to disable autocomplete in <h:inputText>?

I'm making my term paper using JSF 2.0, Java 6 and Tomcat 7, but I'm having some doubts in the development.
In my project I have a <h:inputText> tag
<h:inputText value="#{turmaMBean.nome}">
<f:ajax event="keyup" render=":meuForm:minhaTabela" />
</h:inputText>
I want to disable autocomplete. I already tried:
<h:inputText value="#{turmaMBean.nome}" autocomplete="false">
<f:ajax event="keyup" render=":meuForm:minhaTabela" />
</h:inputText>
However, it didn't work. What can I do to solve this problem?
I found the answer. I searched a lot about this issue and I discover this isn't an issue. When I try to do the following:
<h:inputText value="#{turmaMBean.nome}" autocomplete="off">
<f:ajax event="keyup" render=":meuForm:minhaTabela" />
</h:inputText>
I didn't restart my Tomcat Server, and by some strange way Tomcat doesn't updated my view properly. When I tried to restart the server, this attribute start work.
So, if you need to turn the autocomplete off, use:
autocomplete="off"
This probably will work - don't forget to restart the server, sometimes Tomcat like play with us :p.

setting f:validatelength dynamically does not work

When I use a bean to set the min and max values on f:validatelength it simply does not work. It breaks the functionality in the form so it can't be submitted...
When I outputtext the values they do come out as legit numbers and hardcoding those numbers work fine.
My guess it that it somehow lacks the required connection to beans at that time in the lifecycle or something? (I'm pretty much a beginner). Example below is example of what I want to do
<h:inputSecret id="password" value="#{userBean.user.password}">
<f:validateLength minimum="#{myBean.minSize}" maximum="#{myBean.maxSize}" />
</h:inputSecret>
<h:message for="password" />
I tried using < a4j:keepAlive > on the bean but I couldn't get that to work.
I am using JSF 1.2 with Richfaces 3.3.3 and Seam 2.
Hopefully someone has a clue here. And a good way to achieve this using another tag then that's fine as well! Thanks for reading.
Is the el expression evaluated to integer type?
I have no idea, but you can try a couple of these variations
<h:inputSecret id="password" value="#{userBean.user.password}" maxlength="#{myBean.maxSize}">
<f:validateLength minimum="#{myBean.minSize}"/>
</h:inputSecret>
<h:message for="password" />
<h:inputSecret id="password" value="#{userBean.user.password}" maxlength="#{myBean.maxSize}">
<f:validator validatorId="javax.faces.validator.LengthValidator">
<f:attribute name="minimum" value="#{myBean.minSize}"/>
</f:validator>
</h:inputSecret>
<h:message for="password" />

Check for validation errors in part of a form in JSF

I'm building a Seam application, which is basically a huge form divided into different parts, or modules. I need a way to figure out when a module is "complete", meaning all validation for the fields in that module passes. I then need to do something in the view, setting a css-class or whatever.
Something like:
<a:region id="region1">
<s:div styleClass="#{invalid ? 'errors' : ''}">
<h:inputText required="true" id="input1" />
<h:inputText required="true" id="input2" />
<h:commandButton value="Save this section" reRender="region1" />
</s:div>
</a:region>
I figured I had two options:
Using some sort of view-logic (like #{invalid} for a single field)
Using a method in the bean, where I get all components for the module programmatically, and check them for validation errors.
However, I can't find any way to do any of them. Any ideas if this is even possible?
We're using JSF 1.2 with Seam.
Thanks.
You can use UIInput#isValid() to check if a validation error has occurred on the particular input component.
<s:div styleClass="#{!input1.valid or !input2.valid ? 'errors' : ''}">
<h:inputText binding="#{input1}" required="true" id="input1" />
<h:inputText binding="#{input2}" required="true" id="input2" />
<h:commandButton value="Save this section" reRender="region1" />
</s:div>

Trying to understand why h:commandLink submits through validation and a4j:commandLink doesn't

First of all, i'm using Jsf 1.2...
I have a problem with submitting some values in a form to validation.
Specifically this code segement:
<h:panelGrid columns="4" id="StatusPanel">
<h:outputText value="#{msg.Phone_number_to_send_SMS_to}" />
<h:inputText id="phoneNumber" value="#{general.smsPhoneNumber}" required="true"
requiredMessage="Please enter a valid phone number." />
<a4j:commandLink value="#{msg.Submit_Button}"
reRender="pinCodeDeliveryMsgText, pinCodeDeliveryMsg, pinCodeDeliveryFailedMsg, pinCodeDeliveryMainPanel, LastPinCodeMsg, SendingSMSMSG"
action="#{general.submit}" />
<h:message for="phoneNumber" fatalClass="mandatoryFieldMissing" errorClass="mandatoryFieldMissing" tooltip="true" />
</h:panelGrid>
Which looks like this in the html page:
Whenever I press the submit link, the page doesn't really go through validation, it seems to go with the last successull values instead. The result being that, if the phone number field is left empty, it does nothing and doesn't even render the <h:message> tag.
Actually, I have a workaround fix that looks like this:
<h:commandLink value="#{msg.Submit_Button}">
<a4j:support event="onclick" reRender="pinCodeDeliveryMsgText, pinCodeDeliveryMsg, pinCodeDeliveryFailedMsg, pinCodeDeliveryMainPanel, LastPinCodeMsg, SendingSMSMSG"
action="#{general.submit}"/>
</h:commandLink>
But i'm really curious to know what's the difference between a4j:commandLink and h:commandLink that makes one woirk and the other not.
TnX
Have you tried to set the process attribute of a4j:commandLink to the id of the inputText? Looks like you are just triggering rerendering of some components, so no model update is performed at all.

How to access html components in JSF EL?

I want some code in facelet (jsf 2.0) to work:
<h:inputText id="q" />
<h:button outcome="/search.xhtml?q=#{q.value}" />
but when I press the button, search page opens without any parameters.
I think, my EL expression is wrong. Is it possible to access inputText value from EL expression? If not, how can I achieve the same functionality?
I've finished with using plain html form:
<form action="faces/search.xhtml" method="get">
<input type="text" name="query" />
<input type="submit" value="Find" />
</form>
In search.xhtml I have view param to get a value of query string:
<f:metadata>
<f:viewParam name="query" />
</f:metadata>
This solution has the problem - "faces/search.xhtml" is hardcoded. Also, when I place this form in search.xhtml and perform several searches I have something like this in browser url:
"http://localhost:8080/Application/faces/faces/faces/search.xhtml"
I think this problem can be solved with PrettyFaces (TODO :)
this is a late answer but I guess many people finding this post will have the same doubt whether EL can access html component and how it can:
Yes, EL can access JSF component which are implicit JSF object.
However, up to now I have only seen and used the example of component.valid:
<h:inputText id="streetNumber" value="#{property.streetNumber}" title="streetNumber" required="true" requiredMessage="Please enter the street number!" validatorMessage="Please enter a street number between 1 and 1000" converterMessage="Please enter a number" pt:placeholder="900">
<f:convertNumber integerOnly="true"/>
<f:validateLongRange minimum="1" maximum="1000" />
</h:inputText>
<h:message for="streetNumber" class="#{!streetNumber.valid ? 'label label-warning' : 'none'}" />
So, I suggest you(Dmitry) change the code to
<h:button outcome="#{"/search.xhtml?q=" + q.value}" />
Please let me know whether it works because I am also curious and anyone who faces the similar problem can follow my example and please let me know the result.

Resources