我需要访问在 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。如何在验证方法中获取该对象?
最佳答案
value="#{baseBean.selected}" should be changed as "#{baseBean.value}"
关于java - 如何访问 UIComponent 属性中链接的 bean?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14058905/