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
Related
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.
Should immediate="true" never be used when dealing with an AJAXified JSF 2.0 component?
The example might be:
If I want to implement a "Cancel" button on JSF 2.0 page where if the user hits "Cancel", no validations should run, should I set immediate="true" on the component if it is an ajaxified component or should specify that no components on the form should be processed? If so, what is the way to implement this functionality using the AJAXified features of the component and not the "old way" of using immediate="true"?
Indeed, the purpose of using immediate="true" on a cancel button has become useless since <f:ajax> which you can just set to execute="#this" (which is the default already) to skip the processing of all input components in the same form.
You may only run into problems when the form was already been submitted beforehand but failed due to a conversion/validation failure. If you hit the cancel button by ajax and render the form thereafter, the inputs would still be marked invalid and any changes in the model value are not reflected (you're probably doing a entity = new Entity(); or something in cancel action method to clear out the old values of the form). This problem does not happen when using a synchronous (non-ajax) request with immediate="true". This issue has actually nothing to do with immediate="true", but with the JSF lifecycle of ajax requests. You basically need to reset the invalidated state of the involved input components by calling EditableValueHolder#resetValue() on the components which are not included in the ajax execute, but are included in the ajax render. OmniFaces has a ResetInputAjaxActionListener for exactly this purpose.
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.
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
I'm currently working on a JSF 1.2 project (IBM implementation and a "company layer").
PROBLEM
Here's the situation (numbers of items are just for the example), simple CRUD
List item
I have a list of items
I click on item 2 to see detail
I click on modify, the modification page displays values of item 2
Back to the list with a button "Back" and immediate="true" (because we don't want to submit the modifications)
Detail of item 4
Modify item 4 > Values of item 2 are displayed
BUT
if I set the "immediate" attribute of the "Back" button to false, values of item 4 are OK.
if I set the "disabled" attibute of an inputText component to true, value of item 4 is OK.
if I use <h:outputText value="#{item4.myValue}/> (UIOutput) instead of <h:inputText value="#{item4.myValue}/> (UIInput)
Also, I checked in debug mode that the bean I wanted to display was "item 4" and it was.
WHAT I FOUND
After some research on Google I found that this problem comes from the lifecycle of JSF, although the documentation and solutions found are for specific implementations of JSF.
So I guess it's because the value is populated with "localValue" instead of "submittedValue" (#see EditableValueHolder interface could help understanding), and there are some solutions from these pages
Apache wiki
IceFaces forum
RESULT
It doesn't work (I wouldn't be here, I swear ^^).
The "Refresh" solution is ineffective.
The "Erase input" is scary. I can't admit that I need to reference every input field! Plus I didn't find the setSubmittedValue() method on the UIInput in my IBM JSF.
The "Clear" method is ineffective. I tried on one element, and on the complete component tree with this code
public void cleanAllChildren(List<UIComponentBase> list){
for(UIComponentBase c : list){
this.cleanAllChildren(c.getChildren());
c.getChildren().clear();
}
}
But without success. So here I am.
Did I miss something? is there a nice tricky solution I didn't see? I'm not really familiar with the JSF lifecycle.
Put the bean with request scoped data in request scope, not in session scope.
You probably have the entire list in session to "save" DB calls and all the work to retain values in the subsequent requests inside the same session. You can use a separate session scoped bean for that, e.g. DataManager. Then you should have a request scoped bean to represent the selected item, e.g. DataItem. You can familarize the both beans with help of managed property injection.