【问题标题】:JSF 2.0 Custom Component - how to retrieve object instead of String from ComponentJSF 2.0 自定义组件 - 如何从组件中检索对象而不是字符串
【发布时间】:2011-07-05 07:54:29
【问题描述】:

我正在创建一个自定义组件,其属性接受一个对象的实例 像这样

<hy:bean instance="#{myManagedBean.person}" />

如何在我的渲染器中检索此实例?

我尝试了以下方法,但我只将组件的一个版本转换为字符串

Object instance = beanComponent.getAttributes().get( "instance" );

如果我在下面这样做,我会得到一个 NullpointerException

//expecting "#{myManagedBean.person}" which i can then evaluate
String instance = beanComponent.getInstance(); 

这是BeanComponent中getInstance()的定义

public String getInstance()
{
   return ( String ) getStateHelper().get( PropertyKeys.instance );
}

public void setInstance( String instance )
{
    getStateHelper().put( PropertyKeys.instance, instance );
}

我观察到 Setter 从未被调用过。

知道如何获取#{myManagedBean.person} 的对象进行自省吗?

【问题讨论】:

  • 我觉得你应该尝试提取值绑定而不是值本身。

标签: java jsf-2 custom-component


【解决方案1】:
Object instance = beanComponent.getValueExpression("instance").
                    getValue(context.getELContext());

感谢这个答案 Custom component user object value

【讨论】:

    猜你喜欢
    • 2011-10-11
    • 1970-01-01
    • 2011-10-24
    • 2011-06-24
    • 2018-05-03
    • 2020-03-29
    • 2012-06-27
    • 2010-10-13
    • 1970-01-01
    相关资源
    最近更新 更多