Ok, MyPOJO makes more sense.

But then again, why don't you just use a model:

    public abstract class MyPage extends WebPage {
        public abstract MyPOJO getMyPOJO();
        public onInitialize() {
this.add(new MyPanel("myPanel", new AbstractReadOnlyModel<MyPOJO>() {
                public MyPOJO getObject() {
                    return getMyPOJO();
                }
            }));
        }
    }

No need for any detachable stuff.

Sven

On 05/30/2012 10:44 PM, gmparker2000 wrote:
My quick example isn't real and perhaps a bit misleading.  Actually there is
nothing special about MyModel, its just a POJO that I am wrapping up in a
detachable model.  Maybe I misunderstood what you were trying to tell me.

/** Specialization of MyPage that gets the POJO from a database. */
public class MyRDBMSPage extends MyPage {
     public MyPOJO getMyPOJO() {
         // go get the POJO from the database
     }
     ....
}

/** Specialization of MyPage that gets the POJO from a file. */
public class MyFilePage extends MyPage {
     public MyPOJO getMyPOJO() {
         // go get the POJO from the filesystem
     }
     ....
}

/** Abstract MyPage that doesn't care where the POJO came from (database or
file). */
public abstract class MyPage extends WebPage {
     public abstract MyPOJO getMyPOJO();

     public onInitialize() {
         this.add(new MyPanel("myPanel", this.getMyPOJO()));
         ....
     }
}

/** Panel that has the detachable model. */
public class MyPanel {
     public MyPanel(String id, MyPOJO pojo) {
         MyDetachableModel mdl = new MyDetachableModel(pojo);
         this.add(new CheckBox("myCheckbox", new PropertyModel(mdl,
"isSelected"));
         ....
     }
}

/** Detachable model that needs access to the page. */
public class MyDetachableModel extends LoadableDetachableModel<MyPOJO>  {
         private transient MyPOJO myPOJO;

         public MyDetachableModel(MyModel pojo) {
             // maybe store something from the POJO to help me retrieve the
             // POJO in the load method????

             // I could store a transient reference but that is no good
beyond the initial page
             // render
             this.myPOJO = pojo;
         }

         protected MyPOJO load() {
                 // if I had access to the page I could get the pojo from
there but
                 // it doesn't appear to be available at the point when load
is called.
                 return [GET MY PAGE HERE SOMEHOW].getMyPOJO();
         }
}

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Access-to-Page-from-LoadableDetachableModel-tp4649586p4649590.html
Sent from the Users forum mailing list archive at Nabble.com.

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



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

Reply via email to