I have jsf validation on form where the invalid fields are highlighted based on
styleClass="#{component.valid ? 'reportInput' : 'reportInput_invalid'}"
and a tooltip is being used for displaying the error message as follows
<p:tooltip for="inputFieldId">
<p:message for="inputFieldId" />
</p:tooltip>
Everything works as expected but i want to improve user experience and want to introduce pure client side validation using
<p:clientValidator />
I tried this but it didnt work when onBlur event is fired on inputfield i got the following JS error
'null' is Null or no Object
in validation.js.jsf and the line code is
d.data("uiMessageId",b.attr("id"))
Is it possible to achieve?
An example of my input field is:
<p:inputText id="bic"
styleClass="#{component.valid ? 'reportInput' : 'reportInput_invalid'}"
value="#{bean.bic}"
required="true" requiredMessage="Field value is required" >
<p:watermark for="bic" value="CMHJKLIL" />
<pe:keyFilter regEx="/[a-z0-9]/i" />
<f:validateLength minimum="8" />
<p:clientValidator/>
</p:inputText>
I am using Primefaces 4 with the following maven dependency
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>4.0</version>
</dependency>
Here as it looks in jsf page head section
Here is the validation.js file that is being used
validatuion.js here
i had the exact same error.
it seems that the validator.js code searches for a message container attached to the field, and, if cant find one, it searches one in the nearest form "e.findUIMessage(a,d.closest("form").find("div.ui-message"))"
what you need is to have an tag,
that is, a message assigned for the inputtext, so, when the validator generates an error, it can post the text in that message container.
Related
I am using Primefaces Datatable component. This data table component creates a hidden field dynamically on the browser.
<input type="hidden" id="formId:activitydescription_selection" name="formId:activitydescription_selection" autocomplete="off" value="" />
The Primefaces datatable code is as follows
<p:dataTable id="activitydescription" var="type"
value="#{activityBean.activityList}" rows="#{activityBean.rowNo}" rowKey="#{type.activitySchemeId}"
selection="#{activityBean.activityDTO}"
emptyMessage="No value found with given criteria"
paginatorPosition="bottom" sortMode="single" paginator="#{empty activityBean.activityList ? 'false':'true' }"
dynamic="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
rowIndexVar="rowIndex">
Now when the page is submitted HIDV thinks the hidden field which is created dynamically on the browser is a case of hacking thereby redirecting to error page with the console log as
org.hdiv.logs.Logger log INVALID_PARAMETER_NAME;/hseadmin/pages/secured/admin/Layout.xhtml;**formId:activitydescription_selection**;;0:0:0:0:0:0:0:1;0:0:0:0:0:0:0:1;anonymous
In my hdiv-config.xml file i have modified the file so that HDIV ignore thi validation where this field occurs
<hdiv:paramsWithoutValidation>
<hdiv:mapping url=".*" parameters="formId:activitydescription_selection"/>
</hdiv:paramsWithoutValidation>
But no luck still the same console error and HDIV is redirecting to error page.
Can someone help me out on how to avoid these validations on HDIV?
try..
<property name="userStartParameters">
<list>
<value>hidden1Name</value>
<value>hidden2Name</value>
</list>
</property>
HDIV doesn't support the Primefaces components, only standard JSF components like <h:dataTable>.
http://www.hdiv.org/hdiv-documentation-single/doc.html
I got a simple login form. I am using <p:ajax> to invoke a <p:blockUI> (see this question).
<h:commandButton id="anmeldung_button"
action="#{benutzerAnmeldung.anmelden}" value="Anmelden"
styleClass="btn btn-info btn-sm">
<p:ajax process="#form" update="#form"/>
</h:commandButton>
<p:blockUI id="block" block=":anmeldung" trigger="anmeldung_button" />
I am using <o:highlight /> to highlight invalid inputs. This works fine.
It is working with a <f:ajax> perfectly, too.
Apperently, it is not working with <p:ajax>.
How can I achieve this?
This is caused by <p:ajax> trying to refocus the active element after executing the oncomplete scripts via doEval() (as can be seen in handleReFocus() function in core.ajax.js script. However, when you submit the form by clicking the command button instead of pressing Enter while inside the input, then that active element becomes the command button itself, not the input text. You can confirm this by just using Enter key to submit the form. You'll see that the focus is done right.
There are in your particular case 2 ways to workaround this:
Make use of PrimeFaces' own autofocus facility via <p:focus> which is placed inside the form as below:
<h:form id="anmeldung">
<p:focus context="anmeldung" />
...
</h:form>
It also automatically takes into account invalidated input fields.
Set PrimeFaces.customFocus to true in JavaScript, so that handleReFocus() function won't do its job.
<script>PrimeFaces.customFocus = true;</script>
I am having a problem with an ajax behavior event not being fired immediately as text is typed in a field.
If the field is a String no problem, but I am using a Date.
xhtml:
<h:outputLabel value="Date of Birth:" />
<h:inputText id="searchDOB" value="#{search.dob}" required="true">
<f:ajax event="keyup" listener="#{search.addHyphensToDOB}" render=":output" />
<f:convertDateTime pattern="dd-MMM-yyyy" />
bean:
Date dob;
public void addHyphensToDOB(AjaxBehaviorEvent abe) {
System.out.println("addHyphen");
}
The event is only fired after typing the following:
22-JAN-
And fires on any number after the second hyphen, but not before.
One solution could be to change the Date type to a String, then format without using converter, but I would like to keep the Date type.
Any suggestions, thanks.
Eclipse 3.7, tomcat 7, jsf2.1,
It's not fired because a conversion error has occurred due to invalid date format. The submitted value is converted everytime before the bean listener method is hit. Add a <h:message>/<h:messages> and include its ID in <f:ajax render>. You'll then see it.
A String value of for example 2 can impossibly represent a valid Date object when parsed with the pattern dd-MMM-yyyy.
You'll really need to keep it a String if you want to achieve the functional requirement this way. As a completely different alternative, you could consider to do it entirely at the JavaScript side without sending JSF ajax requests.
I am getting the following error on my Facelet page, which simply consists of an IceFaces form with two fields and two buttons:
The form component needs to have a UIForm in its ancestry. Suggestion: enclose the necessary components within <h:form>
Here is the form:
<ice:form id="form1" partialSubmit="false">
<ice:panelLayout id="panelLayout3">
<ice:graphicImage id="graphicImage1" url="/resources/images/LoginImage.jpg" width="560" />
<ice:outputLabel for="j_username" id="outputLabel1" value="Username:"/>
<ice:outputLabel for="j_password" id="outputLabel2" value="Password:"/>
<ice:inputText binding="#{login.username}" id="j_username" required="true" />
<ice:inputSecret binding="#{login.password}" id="j_password" required="true" />
<ice:commandButton actionListener="#{login.login}" id="loginBtn" value="Login"/>
<ice:commandButton action="#{login.reset}" id="resetBtn" value="Reset"/>
<ice:outputText id="errorMessage" />
<ice:message errorClass="errorMessage" for="j_username" fatalClass="fatalMessage" id="messages1" infoClass="infoMessage" showSummary="false" warnClass="warnMessage"/>
</ice:panelLayout>
</ice:form>
How is this caused and how can I solve it?
This is not an error. This is a warning. The code looks fine, all input components are inside a form, it seems that it should run and work fine. If it indeed works fine, just ignore the warning. This warning is displayed only when the context parameter javax.faces.PROJECT_STAGE is set to Development anyway .
As to the false warning message itself, this check was introduced in Mojarra 2.1.1 as per issue 1663. However, as per issue 2147 it turns out to have some bugs and is been further improved in Mojarra 2.1.3. I'd imagine that the false warning is in your particular case caused by having an <ice:panelLayout> between the form and the input elements.
If you aren't on Mojarra 2.1.3 yet, you may want to consider upgrading to see if it removes the false warning message.
I'm getting this error java.util.NoSuchElementException when i tried to check one of my checkbox under h:selectManycheckBox when i submit the form.
The many checkbox is dynamically populated from the bean. Here is my code.
<h:form id="eF">
<h:inputText id="i" value="#{aklat.suggest}">
<a4j:support event="onkeyup" action="#{aklat.complete}" reRender="m"></a4j:support>
</h:inputText>
<s:div>
<h:selectManyCheckbox value="#{aklat.selectedBooks}" layout="pageDirection" id="m">
<s:selectItems value="#{aklat.books}" var="_book" itemLabel="#{_book}" itemValue="#{_book}" label="#{_book.bookName}"/>
</h:selectManyCheckbox>
<a4j:commandButton value="Add Users" action="#{aklat.fire}"></a4j:commandButton>
</s:div>
</h:form>
The weird part is it renders some data output but when i checked the source code. there are no input type checkbox element.
Is something I am missing.
I assume your managed bean is request scope...
because you are making an ajax request, you have to enable "aklat.books" to persist its value longer than request but shorther than session scope.
If you have tomahawk between your app libraries you can use savestate like this (put it after the h:form tag) :
<t:saveState value="#{aklat.books}"/>
if no tomahawk, you can use a4j:keepAlive:
<a4j:keepAlive beanName = "#{aklat.books}"/>