JSF PRG with validation error - jsf-2

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.

Related

ClientSide Validation on PrimeFaces Wizard

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(); }"

User redirecting in struts2 with data not working

I am new to struts2. I am working on the struts2 with spring application.
I developed user registration functionality. In this registration process have the 3 steps(3forms). First page is step1 contains some fields, second page is step2 contain some other fields and step3 contains some other fields.I used session map in the action class to put the all field values of all forms.After submission form in step3 it goes to call rest service and give the response.If the response is OK then i am redirecting to success page step4. In some cases if user is already exits then it gives response existed user then am redirecting to step5 page. In this page i used one message " Sorry the user is already exists" and with one link "Home Page".
I used this link <s:a id="next" href="/sample/register/user.action"> Homepage </s:a> in step5 page. After clicking on this link it goes to homepage(means step1 page) fine,but it doesn't contain user entered values. I have to maintain all field values in the step1,step2,step3 process. How to achieve this problem.
Please any one can give suggestion.
IF you are using session map to persist values being entered by the user, i believe they should be available in the session until you have not removed them from the session or session expired.more over when you do redirect a new request -response cycle started by the framework and a new value stack will be created that means all old values will be lost.
From your description i believe you are creating a wizard like functionality and if this is the case i believe struts2 provide a more elegant and flexible solution
ScopeInterceptor
This is designed to solve a few simple issues related to wizard-like functionality in Struts
Still you need to show how you trying to show the values in the form being filled by the user if something fails or when user is already exists in the system as described in your case.In this case you need to fetch object/data from the session.

Asp.Net Mvc remote validation textbox focus issue

I have a single textbox on a form - basically to allow users to change the URL of their site in our mini CMS. We use remote validation to check that the URL is not already taken.
They enter their desired URL and hit the save button. If they do just that and the focus goes from the textbox straight to the submit button - the validation does not happen and the form doesn't submit properly. If they tap into an area of whitespace then the form does.
The issue with the form submitting is that if they tap whitespace we get the name of the submit button posted along with the desired URL - we use the (AcceptParameterAttribute) to allow us to route form submits to the right Action. This uses the submit buttons name attribute to do this. If they don't click whitespace to lose focus on the text box then only the desired URL is posted.
This is a really odd one and it is very annoying. Has anyone seen anything like this before? Is there a way to overcome the problem?
Try adding the following script to the page:
$(":input").live("blur", function () {
$(this.form).validate().element(this);
});
This should cause validation to occur when you click on the submit button. If not, try changing the first line to:
$(":submit").live("click", function () {

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.

How do I repopulate everything in a wizard style page for ASP.NET MVC?

I've got a page that creates a ticket in our help desk system. It acts as a wizard with the following steps:
Step 1
User selects the customer from a dropdown list. There is a jquery onchange event that fires and generates the list for step 2 and hides the step1 div and shows the step2 div.
Step 2
User selects the location from a dropdown list. This is generated based on the customer selected in step 1. There is a jquery onchange event that fires and generates the list for step 3 and hides the step2 div and shows the step3 div.
Step 3
User selects the type from a dropdown list and enters text into 3 different text boxes. If the user fails to enter text or enters invalid text my controller changes the model state to invalid and returns the view.
How can I get all the dropdowns to repopulate again with the correct selection the user chose and get the page to redisplay on Step 3?
My first thought was to use ajax and when the user clicks the Create button, I could create the ticket from there and if successful send them to the ticket detail. If unsuccessful, well just display an error message and i'm still on the page so no big deal. Now that I write it out I think this is best. Are there any major issues using ajax? It seems most sites use some type of javascript or ajax these days.
Second thought is to not use ajax at all and submit all the pages to the server.
What do you suggest?
The 3 steps display completely different markup.
There is possibly not much you can gain by an AJAX-version, except the avoided page flicker when you change the steps.
If you go the non-AJAX way you gain:
nice bookmarkable links ( www.ticketsystem.com/Customer -> www.ticketsystem.com/Customer/Microsoft/ -> www.ticketsystem.com/Customer/Microsoft/Location -> www.ticketsystem.com/Customer/Microsoft/Location/Redmond )
browser history works
easier testing
To redisplay the lists after step 3 you would load all of them and set the selected item according to the parameter in the URL.
I agree with you. Use AJAX to submit the ticket.

Resources