2

我需要访问在 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>

爪哇:

@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 方法中获取该对象?

4

1 回答 1

-1
value="#{baseBean.selected}" should be changed as "#{baseBean.value}"
于 2013-04-12T10:37:16.693 回答