开发者

JSF 2.0 Custom Component - how to retrieve object instead of String from Component

开发者 https://www.devze.com 2023-03-17 13:32 出处:网络
I\'m creating a cu开发者_StackOverflowstom component whose attribute accepts an instance of an object

I'm creating a cu开发者_StackOverflowstom component whose attribute accepts an instance of an object like this

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

How do I retrieve this instance in my Renderer?

I tried the following but I only get a version of the component converted to a string

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

If I do below, i get a NullpointerException

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

this is the definition of getInstance() in BeanComponent

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

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

I observed that the Setter is never called.

Any idea how I can get the Object of #{myManagedBean.person} for introspection?


Object instance = beanComponent.getValueExpression("instance").
                    getValue(context.getELContext());

Thanks to this answer Custom component user object value

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号