Extending to all components

2009-01-06 Thread Dane Laverty
Is there an easy way to add/override a function to all my Wicket classes
(panels, pages, forms, etc.)? For example, I have a custom session.
Rather than having to cast (MySession)getSession() , I just want
getSession() to return a MySession. Two solutions come to mind, but
neither seems optimal.

 

First, I could create a MyPanel for all my panels to extend, a MyPage
for all my pages to extend, etc. and have MyPanel and MyPage override
getSession(). However, that means a lot of duplicated code.

 

Second, I could update the Wicket source code, which would be quick and
easy, but then make upgrading Wicket difficult.

 

Is there a simple Java solution that allows me to change/add function
definitions into existing inheritance hierarchies?



Re: Extending to all components

2009-01-06 Thread Scott Swank
We added the following to our Session:

public static final MySession get() {
return (MySession) Session.get();
}

And then we just call MySession.get() instead of calling getSession().

Scott


On Tue, Jan 6, 2009 at 9:59 AM, Dane Laverty danelave...@chemeketa.edu wrote:
 Is there an easy way to add/override a function to all my Wicket classes
 (panels, pages, forms, etc.)? For example, I have a custom session.
 Rather than having to cast (MySession)getSession() , I just want
 getSession() to return a MySession. Two solutions come to mind, but
 neither seems optimal.



 First, I could create a MyPanel for all my panels to extend, a MyPage
 for all my pages to extend, etc. and have MyPanel and MyPage override
 getSession(). However, that means a lot of duplicated code.



 Second, I could update the Wicket source code, which would be quick and
 easy, but then make upgrading Wicket difficult.



 Is there a simple Java solution that allows me to change/add function
 definitions into existing inheritance hierarchies?



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



Re: Extending to all components

2009-01-06 Thread Per Newgro
If i'm not completly wrong there is a Session.get(). You could write a 
Helper which is casting that session instance. So you could use it 
everywhere you want.


SessionConverter.java
public static MySession getConverted() {
 return (MySession) Session.get();
}

and in component where you want to access it
MySession s = SessionConverter.getConverted();

Only an idea.
Cheers
Per

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



Re: Extending to all components

2009-01-06 Thread James Carman
You don't need a helper if you do what Mr. Swank recommended.  With
JDK5, you can have covariant return types.  So, just set up a new
get() method that returns your exact session type.

On Tue, Jan 6, 2009 at 1:11 PM, Per Newgro per.new...@gmx.ch wrote:
 If i'm not completly wrong there is a Session.get(). You could write a
 Helper which is casting that session instance. So you could use it
 everywhere you want.

 SessionConverter.java
 public static MySession getConverted() {
  return (MySession) Session.get();
 }

 and in component where you want to access it
 MySession s = SessionConverter.getConverted();

 Only an idea.
 Cheers
 Per

 -
 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



Re: Extending to all components

2009-01-06 Thread Scott Swank
Since get() is a static method there is no relationship (i.e.
overriding) between MySession.get() and Session.get().  Hence you do
not even need Java 5.


On Tue, Jan 6, 2009 at 10:25 AM, James Carman
jcar...@carmanconsulting.com wrote:
 You don't need a helper if you do what Mr. Swank recommended.  With
 JDK5, you can have covariant return types.  So, just set up a new
 get() method that returns your exact session type.

 On Tue, Jan 6, 2009 at 1:11 PM, Per Newgro per.new...@gmx.ch wrote:
 If i'm not completly wrong there is a Session.get(). You could write a
 Helper which is casting that session instance. So you could use it
 everywhere you want.

 SessionConverter.java
 public static MySession getConverted() {
  return (MySession) Session.get();
 }

 and in component where you want to access it
 MySession s = SessionConverter.getConverted();

 Only an idea.
 Cheers
 Per

 -
 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



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



Re: Extending to all components

2009-01-06 Thread James Carman
Duh!  :)  Good point.

On Tue, Jan 6, 2009 at 1:40 PM, Scott Swank scott.sw...@gmail.com wrote:
 Since get() is a static method there is no relationship (i.e.
 overriding) between MySession.get() and Session.get().  Hence you do
 not even need Java 5.


 On Tue, Jan 6, 2009 at 10:25 AM, James Carman
 jcar...@carmanconsulting.com wrote:
 You don't need a helper if you do what Mr. Swank recommended.  With
 JDK5, you can have covariant return types.  So, just set up a new
 get() method that returns your exact session type.

 On Tue, Jan 6, 2009 at 1:11 PM, Per Newgro per.new...@gmx.ch wrote:
 If i'm not completly wrong there is a Session.get(). You could write a
 Helper which is casting that session instance. So you could use it
 everywhere you want.

 SessionConverter.java
 public static MySession getConverted() {
  return (MySession) Session.get();
 }

 and in component where you want to access it
 MySession s = SessionConverter.getConverted();

 Only an idea.
 Cheers
 Per

 -
 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



 -
 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