提问人:LEON DENIS 提问时间:10/25/2023 最后编辑:BalusCLEON DENIS 更新时间:10/25/2023 访问量:19
JSF 跨字段验证的日期属性 [duplicate]
Date attribute by JSF cross-field validation [duplicate]
问:
我正在将属性传递给另一个字段的验证器。
JSF(Primefaces)
<p:column>
<p:calendar id="IncommingDate"
pattern="dd.MM.yy"
......................................................
binding="#{incommingDate}">
</p:calendar>
</p:column>
<p:column>
<p:calendar id="SolvDate"
pattern="dd.MM.yy"
value="#{complaintBean.solvDate}"
showOn="button"
showButtonPanel="true">
<f:validator validatorId="validation.SolvDateValidator"/>
<f:attribute name="complaintStatus" value="#{complaintStatus}"/>
<f:attribute name="incommingDate" value="#{incommingDate}"/>
</p:calendar>
</p:column>
SolvDateValidator.java
@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException
{
logger.trace("SolvDateValidator:: Start validation");
UIInput incommDate = (UIInput) component.getAttributes().get("incommingDate");
Date incommingDate = (Date) (Objects.isNull(incommingDateUI.getSubmittedValue())
? incommingDateUI.getValue()
: incommingDateUI.getSubmittedValue());
incommingDate 属性是一个日期,但有时它会自发地作为 java.sql.Date (“18.10.2023”) 传递,有时作为字符串传递 (“Wed Oct 18 00:00:00 CEST 2023”)。在第二种情况下,我肯定会得到 ClassCastException
有没有办法严格设置其类型以避免对对象类进行额外检查?
答: 暂无答案
评论