Thanks for your answers, I finally found the "best practice" solution to my 
problem, well, I think so. Remember I was looking for a way to "switch" on/off  
a part of my page (that of course includes declared components in page class 
and in html markup).
I'll try to explain why some approaches aren't the best, imho.

Wanting to "disable" certain components, I think it's quite a repetitive task 
to set empty strings to each and every component I want to hide. Here we only 
have one, but imagine having ten or twelve...
>
> if (product.getPhoto() != null) {
>            add(new Label("product-photo-date", someDateModel));
>        } else {
>            add(new Label("product-photo-date", ""));
> }
>

The same for this, I have to manually override each and every component:
> newLabel("product-photo-date", 
> CommonUtil.getFormattedDate(product.getPhoto().getDateTime())) {
>   public boolean isVisible() {
>     return product.getPhoto() != null;
>   }
> }
>

I couldn't get ideas in  
http://cwiki.apache.org/WICKET/create-dynamic-markup-hierarchies-using-panels.html
 to work.
Wicket complained anyway.

Well... I just came by Fragments... the magical word... that solved my issue:

        Fragment photoFragment = new Fragment("photo-panel", "photo-fragment");
        
        if (product.getPhoto() != null) {
            photoFragment.add(new Label("product-photo-date", someDateModel));
            add(photoFragment);
        } else {
            add(new Label("photo-panel")).setEnabled(false);
        }

So like this we're choosing in Java whether to include a fragment (and its 
childs) or not.

                <span wicket:id="photo-panel">[photo-panel]</span>              
  
                
                <wicket:fragment wicket:id="photo-fragment">            
                        <span 
wicket:id="product-photo-date">[product-photo-date]</span>
                </wicket:fragment>

And that's all to it.

Regards,
Francisco

PS: 
> add(new Label("product-photo-time", new PropertyModel(product, "

> photo.dateTime")));



Yeah, but I needed to handle the Date outputting it formatted with a
SimpleDateFormat. That's why I have
CommonUtil.getFormattedDate(product.getPhoto().getDateTime()).



> But doesn't the product description of dates change after creation of that

> label?

> and also should product be kept into memory?

No, it's just the original photo date coming from exif data, and it
needn't be altered. Thanks for the info cause I'm planning to use it
elsewhere.




        

        
                
___________________________________________________________________________ 
Yahoo! Mail réinvente le mail ! Découvrez le nouveau Yahoo! Mail et son 
interface révolutionnaire.
http://fr.mail.yahoo.com
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to