views:

347

answers:

1

Hi, I have a page with a radio selection with 3 options and a inputTextArea. When i press the submit button on my page, then i need to do some validations... In order to do so, i put a validator on the radio. The problem is that when the validator is executed, i need the values of the inputTextArea and of the radio, but they come with old values, not the ones that were defined on the page before the page was submited.

Example: String.valueOf(textArea.getValue()).equals("")) when it is first sumited the code String.valueOf(textAreaOcorrencia.getValue()) is null, but since the textArea was empty it was suposed to be an empty string. When it is submited for the second time, it has the value of what it was supposed to have in the 1st submission. I know that this has something to do with the JSF life cicle , but i don't know how to update these values?

Thanks in advance...

+2  A: 

During the apply request values phase, the submitted values will be set and available as submittedValue. During the validations phase, the submitted values will be validated and converted and set as value. The components are validated in the top-bottom order as the components appear in the component tree.

Thus, if the component in question actually appears after the current component in the component tree, you'll need to get its value by UIInput#getSubmittedValue() instead of UIInput#getValue().

To learn more about the JSF lifecycle, you may find this self-practice article useful.

BalusC
Hi, i solved my problem this way: Instead of getting the value of the UiComponente this way UIComponent UI = view.findComponent(idComponent); if (UI instanceof HtmlSelectOneRadio){ HtmlSelectOneRadio radio = (HtmlSelectOneRadio) UI; return radio; } ... String.valueOf(radio.getValue()).equals(some object)
Moon13
I did this: Iterator<String> it = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterNames(); while(it.hasNext()){ String requestParameterName = it.next(); if(requestParameterName.equals(idComponent)){ parameterValue = request.getParameter(requestParameterName); } } where idComponent in this loop is the HTML tag ID you have to specify in your jsp, xhtml, whatever page, or else JSF will create a random id each time, and then you won't be able to get the UiComponent you need.
Moon13
That's indeed another way to solve (actually: workaround) the problem. Hauling the raw servlet request parameter map from deep under the JSF hoods which JSF itself has already set as submitted value of the component. Do you for instance **understand** why your way initially didn't work and why my proposed solution fixes your problem? This all makes me a bit to sigh :/
BalusC