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?
精彩评论