Hi, I aggree with Sven. Another option is to pass the panel to the LDM's contructor so you can do a panel.getPage() to get the page. Just cast to the appropriate page type and do yourpage.getMyModel().
Best regards, Sebastien. On Wed, May 30, 2012 at 10:32 PM, Sven Meier <s...@meiers.net> wrote: > > public MyPanel(String id, MyModel model) { > > That looks suspicious, why should MyPanel require a specific model > implementation? > > What's so special about your MyModel? Is it a Wicket model, i.e. > implements IModel? > If yes, then the constructor should look like this: > > public MyPanel(String id, IModel<Foo> model) { > > If not, the following would be my suggestion: > > public MyPanel(String id, IModel<MyModel> model) { > > Hope this helps > Sven > > > On 05/30/2012 10:22 PM, gmparker2000 wrote: > >> I have a situation where I need to access the page from the load method >> of a >> loadableDetachableModel. The loadableDetachableModel is used deep down >> on a >> panel that needs access to the page in order to access the model object. >> To >> complicate things this page is abstract and can be extended to provide >> access to the model differently (i.e. from a database, or from a file). >> It >> kind of looks like this (only more complicated in my case): >> >> /** Specialization of MyPage that gets the model from a database. */ >> public class MyRDBMSPage extends MyPage { >> public MyModel getMyModel() { >> // go get the model from the database >> } >> .... >> } >> >> /** Specialization of MyPage that gets the model from a file. */ >> public class MyFilePage extends MyPage { >> public MyModel getMyModel() { >> // go get the model from the filesystem >> } >> .... >> } >> >> /** Abstract MyPage that doesn't care where the model came from (database >> or >> file). */ >> public abstract class MyPage extends WebPage { >> public abstract MyModel getMyModel(); >> >> public onInitialize() { >> this.add(new MyPanel("myPanel", this.getMyModel())); >> .... >> } >> } >> >> /** Panel that has the detachable model. */ >> public class MyPanel { >> public MyPanel(String id, MyModel model) { >> MyDetachableModel mdl = new MyDetachableModel(model); >> this.add(new CheckBox("myCheckbox", new PropertyModel(mdl, >> "isSelected")); >> .... >> } >> } >> >> /** Detachable model that needs access to the page. */ >> public class MyDetachableModel extends LoadableDetachableModel<**MyModel> >> { >> private transient MyModel myModel; >> >> public MyDetachableModel(MyModel model) { >> // maybe store something from the model to help me retrieve >> the >> // model in the load method???? >> >> // I could store a transient reference but that is no good >> beyond the initial page >> // render >> this.myModel = model; >> } >> >> protected MyModel load() { >> // if I had access to the page I could get the model from >> there but >> // it doesn't appear to be available at the point when >> load >> is called. >> return [GET MY PAGE HERE SOMEHOW].getMyModel(); >> } >> } >> >> It would be great to be able to do this so that different variations on a >> single page could be created easily. Perhaps I am overlooking something >> or >> over complicating this. We are also using spring so it is possible to >> inject (@SpringBean) a bean into the detachable model that provides access >> to the model but I'd rather avoid this as I think it complicates something >> that should be quite simple. >> >> Maybe its just me but I'm finding loadableDetachableModel to be quite >> challenging for my purposes, which are not typically just loading database >> entities. Serializing a key piece of information instead of the model >> makes >> sense and seems rather straightforward but I struggle not with the stuff >> getting serialized but rather the object that is needed to operate on the >> key information to get the model back (i.e a business object, entity >> manager, etc). >> >> If anyone can show me where I'm going wrong I'd appreciate the help >> >> thanks >> >> -- >> View this message in context: http://apache-wicket.1842946.** >> n4.nabble.com/Access-to-Page-**from-LoadableDetachableModel-** >> tp4649586.html<http://apache-wicket.1842946.n4.nabble.com/Access-to-Page-from-LoadableDetachableModel-tp4649586.html> >> Sent from the Users forum mailing list archive at Nabble.com. >> >> ------------------------------**------------------------------**--------- >> To unsubscribe, e-mail: >> users-unsubscribe@wicket.**apache.org<users-unsubscr...@wicket.apache.org> >> For additional commands, e-mail: users-h...@wicket.apache.org >> >> > > ------------------------------**------------------------------**--------- > To unsubscribe, e-mail: > users-unsubscribe@wicket.**apache.org<users-unsubscr...@wicket.apache.org> > For additional commands, e-mail: users-h...@wicket.apache.org > >