what about the LoadableDetachableModel?
 
IModel model = new LoadableDetachableModel() {
    protected Object load() {
        return dao.getX();
    }
};




________________________________
Von: David Chang <david_q_zh...@yahoo.com>
An: users@wicket.apache.org
Gesendet: Montag, den 27. Juli 2009, 14:20:14 Uhr
Betreff: the effective ways of wicket models to access database


Hello, I am reading <<Wicket in Action>> to learn Wicket. The example on Page 
99 is about teaching detachable models. Here it goes:

-----------
public class CheeseModel extends Model {
    private Long id;
    private transient Cheese cheese;
        public CheeseModel() {
    }
    public CheeseModel(Cheese cheese) {
        setObject(cheese);
    }
    public CheeseModel(Long id) {
        this.id = id;
    }
    @Override
    public Object getObject() {
        if(cheese != null) return cheese;
        if(id == null ) {
            cheese = new Cheese();
        } else {
            CheeseDao dao = ...
            cheese = dao.getCheese(id);
    }
    return cheese;
    }
    @Override
    public void setObject(Object object) {
        this. cheese = (Cheese)object;
        id = (cheese == null) ? null : cheese.getId();
    }
    @Override
    public void detach() {
        this. cheese = null;
    }
}
-----------

I would like to know how dao is obtained as indicated as follows:

            CheeseDao dao = ...

Use a locator pattern? Or should I let CheeseModel extend a custom model in 
which dao is set via Spring? Does the latter way create more memory footprint? 
What are the effective ways of getting DAO avaiable to wicket models?

Thanks for your input!

Cheers!


      

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


      

Reply via email to