You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Sergey Podatelev <br...@gmail.com> on 2008/06/26 16:47:55 UTC

Is it okay to use an EmptyPanel for "if"?

Hello,

I'm sorry for this maybe stupid question, but is it okay to use an
EmptyPanel with an empty template in case I want to do an "if" and display
nothing in some cases and contains of a certain panel in all other cases?
I know, this also could be handled by inheritance, but in certain cases an
EmptyPanel looks like a much easier solution, but a bit strange.
Maybe there're any other easier ways to do this?

-- 
sp

Re: Is it okay to use an EmptyPanel for "if"?

Posted by Sergey Podatelev <br...@gmail.com>.
Thanks, Jeremy, I've actually completely forgotten about Wasp/Swarm, which
actually allow me to chose, whether to display a component automatically and
on a deeper level.

On Thu, Jun 26, 2008 at 7:05 PM, Jeremy Thomerson <je...@wickettraining.com>
wrote:

> This is an acceptable solution.  However, there is another way that I
> generally prefer:
>
> Say you have your content panel that you want displayed on some condition,
> for instance, if the model object is not null.    Just do this:
>
> public class ContentPanel extends WebPanel<Foo> {
>    public ContentPanel(String id, IModel<Foo> model) {
>        super(id, model);
>    }
>
>    @Override
>    public boolean isVisible() {
>       return getModelObject() != null;
>       // or, you can do return someOtherCondition.
>    }
> }
>
> This gives you the benefit of the panel automatically appearing if
> something
> else on your page changes the state in a way that makes the condition now
> true.
>
> --
> Jeremy Thomerson
> http://www.wickettraining.com
>
>
> On Thu, Jun 26, 2008 at 9:47 AM, Sergey Podatelev <
> brightnesslevels@gmail.com> wrote:
>
> > Hello,
> >
> > I'm sorry for this maybe stupid question, but is it okay to use an
> > EmptyPanel with an empty template in case I want to do an "if" and
> display
> > nothing in some cases and contains of a certain panel in all other cases?
> > I know, this also could be handled by inheritance, but in certain cases
> an
> > EmptyPanel looks like a much easier solution, but a bit strange.
> > Maybe there're any other easier ways to do this?
> >
> > --
> > sp
> >
>



-- 
sp

Re: Is it okay to use an EmptyPanel for "if"?

Posted by Jeremy Thomerson <je...@wickettraining.com>.
This is an acceptable solution.  However, there is another way that I
generally prefer:

Say you have your content panel that you want displayed on some condition,
for instance, if the model object is not null.    Just do this:

public class ContentPanel extends WebPanel<Foo> {
    public ContentPanel(String id, IModel<Foo> model) {
        super(id, model);
    }

    @Override
    public boolean isVisible() {
       return getModelObject() != null;
       // or, you can do return someOtherCondition.
    }
}

This gives you the benefit of the panel automatically appearing if something
else on your page changes the state in a way that makes the condition now
true.

-- 
Jeremy Thomerson
http://www.wickettraining.com


On Thu, Jun 26, 2008 at 9:47 AM, Sergey Podatelev <
brightnesslevels@gmail.com> wrote:

> Hello,
>
> I'm sorry for this maybe stupid question, but is it okay to use an
> EmptyPanel with an empty template in case I want to do an "if" and display
> nothing in some cases and contains of a certain panel in all other cases?
> I know, this also could be handled by inheritance, but in certain cases an
> EmptyPanel looks like a much easier solution, but a bit strange.
> Maybe there're any other easier ways to do this?
>
> --
> sp
>