【发布时间】:2012-12-13 02:13:43
【问题描述】:
我需要访问在 UIComponent 的 EL 表达式中使用的 bean 对象。
例如,在这个示例代码中:
xhtml:
<h:form>
<f:view>
<p:selectBooleanButton value="#{baseBean.selected}" onLabel="Instalar" offLabel="Ignorar" onIcon="ui-icon-check" offIcon="ui-icon-close">
<f:validator validatorId="baseValidator.items" />
</p:selectBooleanButton>
<p:commandButton type="submit" value="Submit"
actionListener="#{baseBean.process}"
ajax="false" />
</f:view>
</h:form>
java:
@FacesValidator("baseValidator.items")
public static class BaseValidator implements Validator
{
@Override
public void validate(FacesContext context, UIComponent component,
Object value) throws ValidatorException {
ValueReference reference = component.getValueExpression("value").getValueReference(context.getELContext());
Object o1 = reference.getBase();
Object o2 = reference.getProperty();
return; //break point here
}
}
当按下命令按钮时,BaseValidator.validate 被执行,我需要获取<p:selectBooleanButton value="#{baseBean.selected}"> 中使用的baseBean 对象
我的代码当前正在抛出 NullPointerException,因为 getValueReference 正在返回 null。如何在 validate 方法中获取该对象?
【问题讨论】:
标签: java validation jsf-2 primefaces el