wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ondrej Zizka <ozi...@redhat.com>
Subject Label with default text if model empty + CompoundPropertyModel
Date Tue, 19 Feb 2013 05:29:53 GMT
Hi all,

I have:

     public FooPage( ... ) {
        this.setDefaultModel( new CompoundPropertyModel(new 
GenericIdLDM( Foo.class, 1)) );
        add(new Label("title"));

I'd like to have $subj.
I've found this solution from 2007 (point below) : 
http://www.mail-archive.com/wicket-user@lists.sourceforge.net/msg29603.html
However, it wouldn't work for CPM as it needs the constructor with model.

How could I make it CPM?

Thanks,
Ondra


--------

public class DefaultTextModel extends AbstractReadOnlyModel<String> {

     private final IModel<String> delegate;
     private final String def;

     public DefaultTextModel(String def, IModel delegate) {
         this.def = def;
         this.delegate = delegate;
     }

     public String getObject() {
         String s = delegate.getObject();
         return (Strings.isEmpty(s)) ? def : s;
     }

     public void detach() {
         delegate.detach();
     }

}


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


Mime
View raw message