ClientSide Validation on PrimeFaces Wizard - jsf-2

For wizard forms, is there any way we can configure the primefaces 4.0 make and client side validation instead of ajax validation?!
According to user guide the ajax validation is built in:
AJAX and Partial Validations
Switching between steps is based on ajax,
meaning each step is loaded dynamically with ajax. Partial validation
is also built-in, by this way when you click next, only the current
step is validated, if the current step is valid, next tab’s contents
are loaded with ajax. Validations are not executed when flow goes
back.
I think it can be done, if I can call primeface validation manually. Then below code will do the job:
<p:wizard showNavBar="false" widgetVar="wiz">
...
</p:wizard>
<h:outputLink value="#" onclick="PF('wiz').checkClientValidation();">Next</h:outputLink>
<h:outputLink value="#" onclick="PF('wiz').checkClientValidation();">Back</h:outputLink>
Any comments? Can I call client validation manually? Do you think above is good solution!

You can use a commandButton instead of outputLink and set the validateClient=true attribute.
Validations happen in the ValidationsPhase, so its partially client side only.
You don't need to trigger validation manually on the client side.
Is there any reason you have to use the outputLink ?
If you want to check the status of validations on the client side then you can use :
Example :
oncomplete="if (!args.validationFailed){PF('dialogId').show(); }"

Related

Grails form token not available for ajax forms?

In grails it is easy to add tokens to prevent form double submission and also the click hijacking.
Just add useToken="true" to the form tag:
<g:form ... useToken="true" >
But, this is not available for formRemote tag. I know that I can do normal form and write js code to transform them into ajax froms with token, but because of that is odd that is not supported by default in the formRemote tag.
Any reason for this, or is just (another) bug in Grails?

JSF PRG with validation error

I'm using JSF with the PRG pattern. (use in my navigation rules).
The problem is that the redirect is not done (i.e. a post followed by a get of the same page) when I got validation errors (ex : the mandatory value isn't set by the user).
The scenario is :
user doesn't put the mandatory value and submit the form
validation error occurs and the same view is shown with an error
message (no PRG)
the user set the mandatory value and submit ==> GO to the next page
(with PRG)
The user click back button => problem because no PRG was done in the
step 2. ==> Got a "Document Expired" screen in Firefox
Can anyone help me please?
Thanks in advance.
Stéphane
Just submit the form by ajax. It's a matter of adding
<f:ajax execute="#form" render="#form" />
to the command links and buttons. If you're using <h:message(s)>, then I assume that they are in the very same form, otherwise you need to add their client IDs to the render.
Validation errors while submitting the form by ajax won't generate history.

Primefaces & Spring webflow ajax action call

Are there any way to call spring webflow action at primefaces in p:selectOneMenu?
There are two dependent combobox like as primefaces example.(link) But i want to call action which is defined at webflow transtion therefore i could not use p:ajax with actionlistener.
After search,i tried to use p:remoteCommand to call action.It execute action when parent combo change,but it also give captcha validation error (captcha at same form),therefore i set process="#this" to p:remoteCommand, when i set that i could not execute action.
You should be using remoteCommand to invoke SWF action. If you only want to submit a value for some components you can use process="componentIds" to send only the values of specified components. You may also want 'immediate=true' on the remoteCommand to skip JSF validation - this should stop error messages from captcha validation.
However, in my experience its not a good idea to use SWF actions for tasks like refreshing dependent comboboxes. Primefaces partial rendering is much better suited for this, and does not require gimmicks like SWF tags.
Please post your XML if immediate=true does not work.

How to implement a navigation button in JSF 2.0 that doesnt do any validations of anything on the current page?

I want to implement a navigation button that takes the user to another page. I have no desire or need for any validations to run nor for the model to be updated, etc. I have implemented this as an ajaxified client-side redirect (note, I am using Primefaces 3.2).
It works-- but is this the best way to do this?
Navigating from the "onePage.xhtml" to the "anotherPage.xhtml"
onePage.xhtml:
...
<p:commandButton value="Navigate to Another Page"
process="#this"/>
action="anotherPage?faces-redirect=true"
...
Note, I have tried using immediate="true", however Apply Request Values phase still runs, which results in a NPE for me in a getter in my managed bean (as I no longer have the data that my getter needs).
Just use <h:button> or <p:button>. It sends a normal GET request. There's really no need for a POST-Redirect-GET request if it's just page-to-page navigation.
<h:button value="Navigate to Another Page" outcome="anotherPage" />
For the PrimeFaces look'n'feel, just replace h: by p:. Note that this component doesn't require a <h:form>. The link equivalent is the <h:link> (for which there's no PrimeFaces equivalent, there's anyway nothing which needs to be restyled).
See also:
When should I use h:outputLink instead of h:commandLink?
Set attribute immediate to true on commandButton, this will skip all validations, conversions or updates. Attributes causes JSF lifecycle to jump from Apply request values phase directly to Render Response phase.

Validation error messages are shown repeatedly in struts2

I m new to struts2. I am doing client side validation for my form. The error messages for validations that i wrote in properties file are repeated each time i submit.
e.g.
First submit
username required
Second submit
username required
username required
Please tell me how to clear previous error messages?
You should give example from your code. There is a document about Struts2 client side validation and about Ajax Validation there writes:
clearValidationErrors(formNode) : Removes validation errors from a form
so you can try to do it.
If you are using a table on ur jsp to display the form, then make sure that the table is a parent of the form tag. If the table is a child of form tag, the validation messages wont get cleared each time. Making the form tag as a child of table tag would solve your problem.
If you are using the spring integration you have to define your bean as scope="prototype", then you get a new instance of your Action for every request.
It's a good idea to do this for every Action.

Resources