使用<,
f:attribute>您可以将Bean传递给验证器,并以值表达式的形式从组件中检索它。
所以我的输入是这样的(必须使用
<f:validator>而不是上的validator属性
<h:inputText>):
<h:inputText id="containerNum" size="20" maxlength="20" value="#{containerStockAction.containerStock.containerNumber}"> <f:validator validatorId="containerNumberValidator" /> <f:attribute name="containerBean" value="#{containerStockAction.containerStock}"/></h:inputText>和我的验证器类:
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { String containerNumber = (String)value; Object containerBean = component.getValueexpression("containerBean").getValue(context.getELContext()); if(containerBean instanceof BeanA) { //do this }


