On Mon, 25 Feb 2008, Sam Barnum wrote:
> It seems like writing a custom behavior is the right way to do this,  
> but once I call setVisible(false) on a component the beforeRender()  
> method in my behavior doesn't get called anymore, and the component  
> never becomes visible.
...
> DropDownChoice report = new DropDownChoice("report" ; new  
> PropertyModel(this, "selectedReport"), reportOptions );
> 
> WebMarkdupContainer f1 = new WebMarkupContainer("f1");
> f1.add(new AbstractBehavior() {
>       public void onComponentTag(Component component, ComponentTag tag) {
>               // only show the component if it's enabled for the selected 
>               report
>               component.setVisible(selectedReport != null &&  
> selectedReport.isField1Enabled());
>               super.onComponentTag(component, tag);
>       }
> } );

    class ReportDependentWebMarkupContainer extends WebMarkupContainer {
        public ReportDependentWebMarkupContainer(String id) {
            super(id);
        }
    
        @Override public boolean isVisible() {
            if (selectedReport == null) {
                return false;
            }
            return selectedReport.isField1Enabled());
        }
    }
    
    WebMarkupContainer f1 = new ReportDependentWebMarkupContainer("f1");


If you don't want to override isVisible(), you can do
setting the visiblity in Component.onBeforeRender(). 

I'm not sure if you can control visibility in a Behavior,
but have a vague memory that we tried it sometime and
couldn't do it either.

> Should I always keep the component visible and have my behavior  
> replace all the contents after rendering?

No.

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to