Reputation: 20384
Is that correct:
When I query a value before validation (or if validation failed) I have to use getSubmittedValue();
. Once the value is validated, even if I query it in another validation later in the page/control I have to use .getValue();
since getSubmittedValue();
returns null after successful validation?
Upvotes: 1
Views: 4164
Reputation: 21709
This xsnippet makes it easier to handle this. It allows you to just call getComponentValue("inputText1")
to get either value or submittedValue.
Here's the function for reference:
function getComponentValue(id){
var field = getComponent(id);
var value = field.getSubmittedValue();
if( null == value ){
// else not yet submitted
value = field.getValue();
}
return value
}
Upvotes: 3
Reputation: 8086
There's a slightly easier way: if you're just expecting a simple single-value String, just call:
var compare = firstField.getValueAsString();
Otherwise, call:
var compare = com.ibm.xsp.util.FacesUtil.convertValue(facesContext, firstField);
The former calls the latter anyway, but is obviously a terser syntax. This does what you're looking for and more:
Upvotes: 2
Reputation: 20384
Found the answer here. So when you want to ensure that 2 text fields have the same value (use case: please repeat your email) and the first box already has a validation that might fail, you need to use submittedValue unless it is null, then you use the value. Code in the validation expression for the second field looks like this:
var firstField = getComponent("inputText1");
var compare = firstField.getSubmittedValue() || firstField.getValue();
compare == value;
You have to love it.
Upvotes: 0