我在h:inputText字段中使用了vlaidator和valuechangeListener,如下所示。與JSF頁面中的驗證器一起使用時valueChangeListener中的oldValue和newValue
<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) {
}
}
你能顯示驗證碼嗎?因爲如果驗證程序在更改前運行並且未驗證,則它將返回到舊值。 – Lyrion 2013-03-12 09:23:46
你確定你在輸入文本中輸入的內容是有效的嗎? – Lyrion 2013-03-12 12:52:26
是的,它們是有效的 – Yashar 2013-03-12 13:26:41