我需要访问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
,我需要获取baseBean
中使用的<p:selectBooleanButton value="#{baseBean.selected}">
对象
我的代码目前正在抛出NullPointerException
,因为getValueReference
正在返回 null 。如何在validate方法中获取该对象?
答案 0 :(得分:-1)
value="#{baseBean.selected}" should be changed as "#{baseBean.value}"