我在这样的 ah:inputText 字段中使用 vlaidator 和 valuechangeListener。
<h:inputText id="quantityInput" required="true"
validator="#{CartController.validateQuantity}"
value="#{cartLine.quantity}" size="6" maxlength="15"
styleClass="numeric"
onchange='updateAndSubmit("#{CartController.rowIndex +1}", "tabs_root:updatedRow")'
onkeyup='checkEnter(event,"#{CartController.rowIndex +1}", "tabs_root:updatedRow")'
style="margin-right:0.4em"
tabindex="#{CartController.tabIndex}"
valueChangeListener="#{CartController.quantityListener}">
<rd:convertNumber
maxFractionDigits="#{CartController.noOfQuantityDecimals}"
minFractionDigits="#{CartController.noOfQuantityDecimals}" />
</h:inputText>
当我更改 inputText 框时,我在 valuechangeListener 中获得了相同的 oldValue 和 newvalue。当我删除验证器时,这个问题就消失了,当我删除验证器时,我在 valuechangeListener 中获得了正确的 oldValue 和新值。
这是怎么回事,你知道吗?
这是验证器方法
public void validateQuantity(FacesContext facesContext,
UIComponent component, Object value) throws ValidatorException,
Exception {
try {
if (isCurrentRowItem()) {
int quantityValidationResult = quantityControl(value,
getCurrentGoods());
if (quantityValidationResult != QUANTITY_OK) {
setViewErrorColumn(true);
FacesMessage msg = new FacesMessage();
if (quantityValidationResult == QUANTITY_TO_LOW) {
String felTextMiQuant = Text.get(
TextProperties.ANGIVENKVANTITETMINDREBESTKVANT,
getApUserData().getUser().getCultureSetting());
msg.setSummary(felTextMiQuant + " " + minQuantity);
getActiveCartAndTemplateTab().getErrorList().put(
new Integer(getRowIndex()), msg.getDetail());
} else {
String felTextMuQuant = Text
.get(TextProperties.ANGIVENKVANTITETEJTILLATENMULTIPEL,
getApUserData().getUser()
.getCultureSetting());
msg.setSummary(felTextMuQuant + " " + multipleQuantity);
getActiveCartAndTemplateTab().getErrorList().put(
new Integer(getRowIndex()), msg.getDetail());
}
// Activate the previous tab, the one containing the errors,
// in case the user tries to activate another
if (cartAndTemplateController != null)
cartAndTemplateController
.setActiveTab(cartAndTemplateController
.getActiveTab());
throw new ValidatorException(msg);
} else {
// if we don't set here it will be impossible to correct more then one error
double valueAsDouble;
Line line = (Line) getCartEntity()
.getLines(getApUserData()).get(validatorCounter);
if (value instanceof Long) {
valueAsDouble = ((Long) value).doubleValue();
}
else if (value instanceof String){
valueAsDouble = Double.parseDouble((String) value);
}
else {
valueAsDouble = (Double) value;
}
line.setQuantity(getApUserData(), valueAsDouble);
}
validatorCounter++;
}
} catch (IllegalArgumentException e) {
}
}