I'm writing a form (non-ajax) in which a selection from a DropDownChoice makes various other items on the form visible or invisible.

I'd like to bind this behavior up lazily using properties, instead of making field variables for all the visible/invisible components.

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.

Here's a sketch of the code:

Form form = new Form("form");
add(form);
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);
        }
} );
form.add(f1);
f1.add(new TextField("myTextField"));

It seems like the isTemporary() method in my behavior gets called, even if the component is invisible. This hardly seems like the right place to put the code, though.

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

-Sam Barnum

Reply via email to