Input fields hold previous values only if validation failed

This problem is in JSF 2 also recognized and explained in detail in the following answer: How can I populate a text field using PrimeFaces AJAX after validation errors occur? If you were using JSF 2, you could have used OmniFaces’ ResetInputAjaxActionListener or PrimeFaces’ <p:resetInput> or resetValues="true" for this.

To the point, you need to clear the state of the EditableValueHolder component when it’s about to be ajax-rendered, but which isn’t included in the ajax-execute. To clear the state, in JSF 2 you would have used the convenience method resetValue() for this, but this isn’t available in JSF 1.2 and you need to invoke the 4 individual methods setValue(null), setSubmittedValue(null), setLocalValueSet(false), setValid(true) to clear the state.

To figure out which components are to be ajax-rendered, but aren’t been ajax-executed, in JSF 2 you would have used PartialViewContext methods for this, but this is not available in JSF 1.2 which hasn’t standardized ajax yet. You’d need to fiddle with RichFaces specific ajax API in order to figure that. I can’t tell that from top of head, so here’s a kickoff example assuming that you already know the components which needs to be cleared. Imagine that the form in your popup has id="popForm" and the name input field has id="nameInput", here’s how you could clear it inside the newData() method:

UIInput nameInput = (UIInput) context.getViewRoot().findComponent("popForm:nameInput");
nameInput.setValue(null);
nameInput.setSubmittedValue(null);
nameInput.setLocalValueSet(false);
nameInput.setValid(true);

Leave a Comment