开发者

Jsf 2.0 dynamically remove component from view

I am trying to replace a component in the view using the PreRenderViewEvent but it doesn't work. The replaced component still renders.

Here is the code I'm using

    CommandButton toRender = ( CommandButton ) ctx.getApplication().
            createComponent(
            "org.primefaces.component.CommandButton" );
    toRender.setAjax( false );
    toRender.setLabel( "View" );
    toRender.getAttributes().put( "TargetState", State.table );
    toRender.setValue( State.table );
    if ( getToRender() != null )
    {
        getChildren().remove( getToRender() );
        getToRender().setParent( null );
    }
    getChildren().add( toRender );
    setToRender( toRender );

and here is the getter and setter for the current component

public UIComponent getToRender()
{
    return ( UIComponent ) getStateHelper().eval( PropertyKeys.toRender,
            null );
}

public void setToRender( UIComponent toRender )
{
    getStateHelper().put( PropertyKeys.toRender, toRender );
    开发者_如何学JAVAhandleAttribute( "toRender", toRender );
}

Any ideas how I can achieve this?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜