我的 Seam 项目中有以下 xhtml 代码:
<rich:column style="text-align:right">
<h:inputText id="txtPercReqAmount" maxlength="6" style="width:75px;text-align:right;" value="#{pib.reservedPercentage}">
<a4j:support event="onchange" ajaxSingle="true" action="#{requestForm.onReservedPercentageChange(pib)}" reRender="txtReqAmount,txtBudget,msgPercReqAmount"/>
</h:inputText>
</rich:column>
<rich:column width="250px" style="text-align:left">
<rich:message id="msgPercReqAmount" for="txtPercReqAmount" styleClass="messagesingle" errorClass="errormsg" infoClass="infomsg" warnClass="warnmsg">
<f:facet name="errorMarker"><h:graphicImage url="/img/msgerror.png"/></f:facet>
</rich:message>
</rich:column>
我在 inputText 的“onchange”事件中进行了一些验证。如果验证失败,我想在<rich:message>
列中写入错误消息。这是我的支持 bean 事件的 java 代码:
public void onReservedPercentageChange(ProcessInstanceBudget pib) {
BigDecimal arg2 = pib.getReservedPercentage();
BigDecimal ra;
try
{
if (arg2 instanceof BigDecimal)
ra = (BigDecimal) arg2;
else
ra = BigDecimal.ZERO;
}
catch (ClassCastException cce)
{
facesMessages.add(Severity.ERROR, "The allocation request isn't valid!");
return;
}
if (ra.compareTo(BigDecimal.ZERO) < 0 || ra.compareTo(new BigDecimal(100.0)) > 0) {
facesMessages.add(Severity.ERROR, "Allocation percentage must be in the range between 0 and 100!");
return;
}
updateBudgetAllocation(pib);
}
问题是未显示错误消息(我没有收到“FacesMessage(s) 已入队,但可能未显示”之类的警告)。
我无法弄清楚我的代码有什么问题。有人可以帮忙吗?