JSF 2.0 Validation Summary Message - validation

Using JSF 2.0 validation, is there a way to have a summary message on submit if there is an error (as well as keeping individual form element error messages)?
I have a large form so the problem I am encountering is that when the user clicks "SUBMIT" it will display the error information next to each individual form element but the user cannot easily tell that errors exist on the page.
Along the lines, what is the common or recommended practice?

How about this?
<h:outputText value="There are messages" rendered="#{not empty facesContext.messageList}" />
Alternatively you can also just use JavaScript to put focus on the first invalid input element. That's a more common practice.

I generally use
<h:messages>
at the top of the page along with label attribute of components to describe each component in error message.
link here
and here might be useful

Related

How to stop next ajax request until current one get completed?

Hi In my project I have input text box like following, where on "keyup" event I am making a call to managed bean where I perform searching operation in a arraylist.
That arraylist I show in p:dataTable which is named as userDataTable
My Code for xhtml
<p:inputText id="searchText" binding="#{searchText}"
value="#{userData.searchReq}" autocomplete="off">
<p:ajax listener="#{userManagement.userTable.searchListener}"
event="keyup" update="userDataTable/>
</p:inputText>
This basically gives user to perform filtering on table when he types in inputText. But problem is user can type very fast. I want to stop next ajax call until current ajax call completed. How I can achieve that?
Since you're already using Primefaces, you can use the AutoComplete component to perform exactly what you're ttrying to do. The first example shows a basic autocomplete functionality using arraylists.... you may refer that.
Autocomplete also has the feature of delaying your hit to the server to compensate for fast typing - the queryDelay attribute. Refer to the User Guide for complete details.

Can't change spring webflow state if jsf client side validation fails

I have a simple form for creating a record - it has some fields which are required and two buttons, one for submit and one for cancel. The problem is that cancel button is not working (it actually always reloads the view for creating record), unless all required fields are entered.
Field looks like this
<h:inputText id="name"
value="#{userController.User.name}"
required="true"
requiredMessage="This field is required"
maxlength="11" tabindex="22" />
In spring webflow definition i added validation="false", also tried binding="false", but it didn't help, although I'm not sure if it is relevant, as I have problem with jsf validation, not spring webflow validation.
Also to add that I'm using Richfaces 4, it might be useful information.
Thanks in advance for your answers.
Stefan
Your problem is not related to Spring Webflows or Richfaces, but to the standard JSF lifecycle that handles every request to the server.
This cycle consists of several phases (google "jsf lifecycle" for plenty of illustrations and explanations). One of them is processing all validators. If validation fails, the cycle will be aborted and a response (current page + messages) is sent. The method invocation phase, which would process your cancel button, will not be reached.
When adding immediate=true to the button it will move the processing of this button to the process validations phase, hence it will be called before processing the validation failure events (and thus the re-rendering of the page).
Try adding immediate="true" to your Cancel button XHTML

ValidationGroup easy explanation

Can someone help me with this line of code and tell me what it is looking for? This chunk of code is associated with a text box control on my page.
ValidationGroup="<%# ((TSAPassenger)((RepeaterItem) Container.Parent.Parent).DataItem).PaxKey %>" runat="server" ErrorMessage="Invalid Contact Name.">
When a postback occurs (via a button press, autopostback dropdown list, etc), ASP.NET will validate all inputs for the validation group specified on the control that caused the postback.
That line of code is grabbing the 'PaxKey' property of the data item for the repeater item two levels up in the control tree that contains the text box and using it to specify the validation group the textbox belongs to. This is likely there to limit the validation to just the fields for the record you're updating (as opposed to everything on the page).

JSF 2.0 values not being submitted

I’m struggling to get my bean to update with the new page values. I have two submit buttons on my page and I toggle which one displays based on a Boolean value for what mode my page is in. When my page is in update only (no validation) I show the submit button that has immediate=”true”. When the page is in process mode (validate) I show the submit button that does not have immediate=”true”.
The problem I’m running into is when I am in update mode (no validation) the values in the input fields are not being set in the bean. All I want to do when in this mode is save the page as is and exit. No validation is needed because the information on that page is not ready to process or “really use” if you will. That said, if I have my page in process mode (validate) then everything works as intended. Values are submitted and saved.
I’m not posting any code yet as there is nothing special about what I’m trying to do. I simply have a value binding that points to simple getter / setter. My bean is in #ViewScope.
I’ve tried using the examples by BalusC in his excellent blogspot post: debug-jsf-lifecycle.
Putting immediate=”true” on the input fields has no affect when clicking on the submit button with immediate="true". All and all though, the way I understand it is immediate=”true” on the UICommand is what tells the application to skip validation or not. Putting it on the input fields simply makes validation happen sooner. Am I missing something?
Any ideas? Any and all help with this is most appreciated!
App specifics:
JSF 2.0.3
Tomcat 6.0.14
The immediate="true" is not intented to disable validation. It's intented to either prioritize validation or to skip processing of the input altogether. See also the summary at the bottom of the article.
You need to disable validation by setting required="false", or <f:validator disabled="true">. Here's an example which assumes that you've a boolean process property which represents the form's state:
<h:inputText value="#{bean.value1}" required="#{bean.process}" />
<h:inputText value="#{bean.value2}" required="#{bean.process}">
<f:validator validatorId="someValidatorId" disabled="#{!bean.process}" />
</h:inputText>
...
This way the fields aren't required and won't be validated when process evaluates false.

Bypass JSF validation for a UIInput component

Here is the issue, JSF validation keeps flipping a field back to the last known value.
We are editing a page where the backing bean already has values.
(frequency = "weekly")
And we are required to show the default value of "please select.." even though that value will not pass validation (yes, I just want to leave the user on the page with the error message).
Is there any way to allow the user to choose "Select.." and not reset it to the last good value?
The user wont be allowed to save obviously, but we want to leave their invalid value selected.
User adds new object, selecting proper value from drop down
User saves successfully.
User Clicks "edit" and displays object with known value ("weekly")
User changes "weekly" to "select"
User clicks save
Validation message is shown (good) but frequency goes back to last value "weekly" (bad, I need it to stay on "Please select.." and let the user fix the drop down manually.
immediate="true" does not work on inputComponents, only commandComponents.
I recognize this, I've reported this more than one year ago as JSF issue 1299. This is still not resolved since it has a low priority. This is not specific to all UIInput components, but to MenuRenderer which is responsible for rendering the HTML <select> elements. All other HTML input elements behave as you would expect, the submitted value will be redisplayed (well, which is actually nothing as well).
Since you're already on JSF 2.0, I suggest you to solve this with a little help of f:ajax so that the dropdown won't be re-rendered and thus keeps its selection.
<h:selectOneMenu id="frequency" value="#{bean.frequency}" required="true">
<f:selectItems value="#{bean.frequencies}" />
<f:ajax render="frequencyMessage" />
</h:selectOneMenu>
<h:message id="frequencyMessage" for="frequency" />
The additional benefit is that the enduser has instant feedback and this is better for user experience.

Resources