You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Kaspar Fischer <fi...@inf.ethz.ch> on 2008/02/26 10:47:06 UTC

[Newbie question] How to avoid empty boxes?

I have just started looking at Wicket and have a basic question.

My page displays an article with meta-data from the database. I  
display the
meta-data in a box (a <div>...</div>). If no meta-information is  
present,
I don't want the box (the <div>) to appear at all. Is there a generic,
Wicket-style way for achieving this?

I struggle with two things here:

* How to do the conditional markup? (For instance, if the article has no
   author meta-information, I don't want to show "Authors: " in the  
box.)
* How to avoid empty boxes? (The box component would have to buffer its
   markup and check, in the end, whether it is nothing but whitespace.)

Thanks for any pointers.
Kaspar

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: [Newbie question] How to avoid empty boxes?

Posted by Kaspar Fischer <fi...@inf.ethz.ch>.
Another possibility:

/**
  * A panel whose visibility is on iff at least one of its  
subcomponents is visible.
  */
public class Envelope extends Panel
{
   private static final long serialVersionUID = -6422145787799831814L;

   public Envelope(String id)
   {
     super(id);
   }

   public Envelope(String id, IModel model)
   {
     super(id, model);
   }

   @Override
   public boolean isVisible()
   {
     boolean visible = false;

     for (Iterator<Component> it = iterator(); it.hasNext();)
     {
       Component child = it.next();
       if (child.isVisible())
         visible = true;
     }
     return visible && super.isVisible();
   }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: [Newbie question] How to avoid empty boxes?

Posted by Kaspar Fischer <fi...@inf.ethz.ch>.
Dear Bernd, Gerolf, Nino,

Thanks a lot for your replies: in two minutes I learnt a lot!

For my particular needs, wicket:enclosure is not the perfect solution:
I have several children,

   <wicket:enclosure child='child1'>
     <div wicket:id="child1"></div>
     <div wicket:id="child2"></div>
   </wicket:enclosure>

but using the child='...' syntax, the visibility is coupled to a  
specific
child while I need child1.visible OR child2.visible OR ... .

So I'll go with Nino's setVisible(false) approach.

Thanks a lot for the feedback! Much appreciated. - Kaspar

On 26.02.2008, at 11:06, Nino Saturnino Martinez Vazquez Wael wrote:

> hmm why do it complicated, just create a panel, and if your rules  
> decide it then call setvisible(false)... then no markup will be  
> visible from that component...
>
> Kaspar Fischer wrote:
>> I have just started looking at Wicket and have a basic question.
>>
>> My page displays an article with meta-data from the database. I  
>> display the
>> meta-data in a box (a <div>...</div>). If no meta-information is  
>> present,
>> I don't want the box (the <div>) to appear at all. Is there a  
>> generic,
>> Wicket-style way for achieving this?
>>
>> I struggle with two things here:
>>
>> * How to do the conditional markup? (For instance, if the article  
>> has no
>>   author meta-information, I don't want to show "Authors: " in the  
>> box.)
>> * How to avoid empty boxes? (The box component would have to  
>> buffer its
>>   markup and check, in the end, whether it is nothing but  
>> whitespace.)
>>
>> Thanks for any pointers.
>> Kaspar
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
> -- 
> Nino Martinez Wael
> Java Specialist @ Jayway DK
> http://www.jayway.dk
> +45 2936 7684
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: [Newbie question] How to avoid empty boxes?

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
hmm why do it complicated, just create a panel, and if your rules decide 
it then call setvisible(false)... then no markup will be visible from 
that component...

Kaspar Fischer wrote:
> I have just started looking at Wicket and have a basic question.
>
> My page displays an article with meta-data from the database. I 
> display the
> meta-data in a box (a <div>...</div>). If no meta-information is present,
> I don't want the box (the <div>) to appear at all. Is there a generic,
> Wicket-style way for achieving this?
>
> I struggle with two things here:
>
> * How to do the conditional markup? (For instance, if the article has no
>   author meta-information, I don't want to show "Authors: " in the box.)
> * How to avoid empty boxes? (The box component would have to buffer its
>   markup and check, in the end, whether it is nothing but whitespace.)
>
> Thanks for any pointers.
> Kaspar
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

-- 
Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: [Newbie question] How to avoid empty boxes?

Posted by Gerolf Seitz <ge...@gmail.com>.
hi,
if no ajax is involved, i suggest reading [0] about wicket:enclosure.
this should do the trick.

cheers,
  gerolf

[0] http://www.systemmobile.com/?page_id=253

On Tue, Feb 26, 2008 at 10:47 AM, Kaspar Fischer <fi...@inf.ethz.ch>
wrote:

> I have just started looking at Wicket and have a basic question.
>
> My page displays an article with meta-data from the database. I
> display the
> meta-data in a box (a <div>...</div>). If no meta-information is
> present,
> I don't want the box (the <div>) to appear at all. Is there a generic,
> Wicket-style way for achieving this?
>
> I struggle with two things here:
>
> * How to do the conditional markup? (For instance, if the article has no
>   author meta-information, I don't want to show "Authors: " in the
> box.)
> * How to avoid empty boxes? (The box component would have to buffer its
>   markup and check, in the end, whether it is nothing but whitespace.)
>
> Thanks for any pointers.
> Kaspar
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>